6/21/2009

Little frustration with SOAP web service

Today I tried to prototype a soap client in C#. While Visual Studio works like a champ, my web services calls seem to be creating new session every time. I tried to look for info for this subject, but didn’t have too much luck yet, marked today a day of minor frustration…

 

---- Resolved 06/21/2009…well, kind of ----

Ok, the problem was worked around referring to this article:

http://www.galasoft-lb.ch/mydotnet/WpfTests.TestSessionId/index.html

In short, the problem is, session relies on cookie, and cookie is disabled by default. Therefore, the solution is to enable cookie by instantiating a System.Net.CookieContainer and assign to your web service objects .CookieContainer property.

But there is a trick: It assumes the generated web service object derived from SoapHttpClientProtocol instead of anything else. In tools like WSDL, SoapHttpClientProtocol is exactly the base class so no problem. However, if you, like me, used Visual Studio to generate the proxy by choosing [Project/Add Web Reference], then sorry, no SoapHttpClientProtocol.

The reason I marked this as “kind of resolved” is because I really want to enable the scenario for code that’s generated by Visual Studio [Project/Add Web Reference]. After all, these are all just some HTTP sessions created and tossed around between client and server, so hack, it really leave a bad taste in my mouth until I could do exactly what I want in all cases…

沒有留言: