问题
I have a webservice, it has its wsdl and everything works fine when I make a call to my web service.
What I want to do now is call a url from somewhere within my web service method. In c# code behind I can do it something like this:
Response.Redirect("Insurance.aspx?fileno1=" + txtFileNo1.Text + "&fileno2=" + txtFileNo2.Text + "&docid=" + Convert.ToString(GridView1.SelectedDataKey[2]));
but the Response.Redirect option is not available on the asmx page.
Is something like this possible? If so then would be grateful in anybody can show me how. I've tried searching everywhere but can only find about calling a web service or calling a webs ervice inside another web service but no such topics on calling a url from within your web service. Any help would be greatly appreciated.
回答1:
The Response.Redirect
method sends a Status Code 300 to the browser which directs the user to a new page. What you want to do is create a WebRequest
and parse the response:
string url = string.Format("www.insuranceini.com/insurance.asp?fileno1={0}", txtfileno1);
WebRequest request = HttpWebRequest.Create(url);
using(WebResponse response = request.GetResponse())
{
using(StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string urlText = reader.ReadToEnd();
//Do whatever you need to do
}
}
EDIT: I wrapped the WebResponse and StreamReader objects in using statements so they are disposed of properly once you're finished with them.
来源:https://stackoverflow.com/questions/12378386/webservice-method-to-call-a-url