Today in helping colleagues resolve the problem of Web References calls to WebService: when calling WebService first method Method1 Discovery server set-cookie:asp.net_sessionid=***** asp.net session state is saved. Then, when I call WebService's second method Method2, I find that the server-side processing results are not returned correctly
That is, the webservices does not respond properly to the server when the HTTP post is performed. The sense problem is on the Cookie (the METHOD1 is Set-cookie at the time of the call), but it's not always going to solve the problem. Then test webservices browser-side access, everything is normal. Only blame oneself to webservice to know very little, cause obviously know the problem lies, just can't solve the problem.
Technical problems are always the case, and the more you want to solve it, the harder it will be to get it done quickly. So after coming home from work, take a shower, and then try to solve the problem. I suddenly thought of long ago I wrote an article, is the HTTP grab bag article, the article address here: http://www.cnblogs.com/ryanding/archive/2011/01/17/1936392.html. Mainly through the HttpWebRequest, HttpWebResponse these two major artifacts to solve the problem. Then think of it as a sure way to fix the problem. But it's a little too cumbersome. Remember HttpWebRequest has a Cookiecontainer object that can solve the cookie problem. So desperately trying to find the relevant properties on the Webservcie Web references instantiation object. Finally I solved the perfect, the code is as follows:
Copy Code code as follows:
ConsoleApplication1.WebReference.YourWebServiceName proxy= New ConsoleApplication1.WebReference.YourWebServiceName ();
System.Net.CookieContainer Cookies = new System.Net.CookieContainer ();
Proxy. Cookiecontainer = Cookies;
The code executes the above information in the execution Method1, because this thing just starts set-cookie ...
Then in the execution Method2 everything is OK.
This illustrates the proxy. Cookiecontainer stores the Asp.net_sessionid of the client. This then passes the Asp.net_sessionid to the server side each time it is called by the WebService method.
Note: The webservices is provided by the customer and we cannot modify its code arbitrarily.
I think a lot of people have encountered similar problems. This article right when convenient Up-and bar.