asp.net webservice the use of Asp.net_sessionid in the problem description _ Practical Skills

Source: Internet
Author: User
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.

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.