Skip to content

Instantly share code, notes, and snippets.

@premsh
Created June 17, 2013 18:48
Show Gist options
  • Save premsh/5799268 to your computer and use it in GitHub Desktop.
Save premsh/5799268 to your computer and use it in GitHub Desktop.
Proxy Web Service
[WebService(Namespace = "Foo")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class GetData : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string GetInfo()
{
string proxyURL =
"http://foo.svc?$format=json";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(proxyURL);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode.ToString().ToLower() == "ok")
{
Stream content = response.GetResponseStream();
StreamReader contentReader = new StreamReader(content);
return contentReader.ReadToEnd();
}
return string.Empty;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment