ASP. NET_SessionId in ASP. NET WebService

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.