Today, I am helping my colleagues solve the Web References call problem for WebService: when the first webservice method Method1 is called, the server Set-Cookie: ASP is found. NET_SessionId = ***** saves ASP.. NET session status. Then, when I call the second webservice method Method2, I find that the server processing result cannot be returned correctly.
That is to say, when webservices performs http post, it cannot respond to the server normally. It seems that the problem lies in the cookie (Set-Cookie is performed on the server when Method1 is called), but the problem still cannot be solved. Then test the webservices browser access. Everything is normal. I only blame myself for having little knowledge about WebService, which makes it impossible to solve the problem because the problem is clearly known ..
This is often the case for technical problems. The more you want to solve it, the more difficult it will be. As a result, when I got home from work, I continued to try to solve the problem. I suddenly thought of long ago and wrote an article about http packet capture. The article is here: http://www.cnblogs.com/ryanding/archive/2011/01/17/1936392.html. It mainly uses the HttpWebRequest and HttpWebResponse artifacts to solve the problem. Later, I think this will certainly solve this problem. But it is a little too cumbersome. Remember that HttpWebRequest has a CookieContainer object, which can solve the cookie problem. As a result, we tried our best to find relevant attributes on the Web References instantiated object of WebServcie. The Code is as follows:
Copy codeThe Code is as follows:
ConsoleApplication1.WebReference. YourWebServiceName proxy = new ConsoleApplication1.WebReference. YourWebServiceName ();
System. Net. CookieContainer Cookies = new System. Net. CookieContainer ();
Proxy. CookieContainer = Cookies;
After the code is executed, the above information is executed in Method1, because this stuff starts Set-Cookie...
After executing Method2, everything is OK.
This indicates that proxy. CookieContainer stores the ASP. NET_SessionId of the client. In this way, ASP. NET_SessionId will be passed to the server every time you call the webservice method.
Note: This WebService is provided by the customer and we cannot modify its code at will.
I think many people have encountered similar problems. This article is convenient for later users.