Search

Consuming CGI webService

 
Func cgiService = (xx_1,xx_2) =>
{
// Build Query URL
QueryUrl = "http://www.url.htm?xx1=" + xx_1 + "&xx2=" + xx_2;

// If required by the server, set the credentials.
WebRequest request = WebRequest.Create(QueryUrl);
request.Credentials = CredentialCache.DefaultCredentials;

// Get the response.
WebResponse response = request.GetResponse();

// Display the status.
//Response.Write(((HttpWebResponse)_response).StatusDescription);

// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();

// Open the stream using a StreamReader for easy access.
if (dataStream != null)
{
StreamReader reader = new StreamReader(dataStream);

// Read the content.
ResponseFromServer = reader.ReadToEnd();

// Display the content.
//Response.Write(ResponseFromServer);

ResponseFromServer = ResponseFromServer.Substring(59, ResponseFromServer.Length - 59);

// Clean up the streams and the response.
reader.Close();
}
response.Close();
return ResponseFromServer;
};

// how to call
string result = cgiService("query1","query2");