Link to home
Start Free TrialLog in
Avatar of calinutz
calinutzFlag for Romania

asked on

Cookie container

I am developing an application that would use many external web services. One of the webservices I need to use, is not stateless. So it defines and uses session state variables. Because of this reason, my client application has to permit the usage of cookies. Or as I am being told by the web service server application :
"For client applications that do not use cookies (for example Windows Forms applications) you can use objects of type CookieContainer"
The problem is that I am not able to access the full functionality of the webservice without using these cookies.
As far as I know... there is no such object type in Delphi.
I am open to suggestions (with code snippets of course)

Avatar of ebob42
ebob42
Flag of Netherlands image

After you import the web service, and you create an instance of the proxy, let's say in variable WS, then you can create a new CookieContainer for the WS.CookieContainer property.

CookieContainer is defined in the System.Web.Services.Protocols namespace.
Note that CookieContainer should only be needed if you use Delphi Prism or an older Delphi for .NET client.

When using Delphi for Win32, there is no need for a cookieContainer, since the Win32 client will automatically accept the cookies for you.
Avatar of calinutz

ASKER

I use delphi 2010 (not .NET nor Prism)... so I have no access to the cookie container.
And as for Delphi I have problems with obtaining a correct result from a web service function, and the people from the server told me it's because of the cookies...
Suggestions?
Dear Mr. Bob I was not expecting you to show up here and try to help me out. (I am a fan of your website). I have probably read all your articles about SOAP and Delphi, and I based my client app on hints from your articles (and other sources).
Please get back to me with a solution for this problem. I'm counting on your expertise in using SOAP with Delphi ;)

I assume Delphi 2010 does not use the cookies correctly (in my case to say the least).

To make things short, the webservice has a few functions (5)... I need to use 2 of them. After calling the first function, I must call the second function... (with the same arguments). Apparently it is necessary  to call the first function before calling the second. But when I call the functions... I call the first one... ok, then I call the second... and I receive an error message saying that I did not call the first function.

Based on the hint about the cookies, that the web service owners previously sent to me, I assume that there should be a cookie filled with something in the back after calling function one ... cookie that is used by the function two.

Thanks
I'm not sure why Delphi 2010 doesn't handle the cookies correcrlt.

Do you have a WSDL example or location, so I can try to import and build a client myself? Or is this a private web service?
It is private... I could give the credentials and WSDL to you, but not publicly...
Tell me how to do it, and I'll do it...
Of course, the conclusions will be posted here... only without the sensitive information.
Thank you and I will be waiting for your post with the communications means to use to pass you the WSDL and credentials
Send me an email on my email (from my profile) and I'll reply with the informations.
I have sent you the test project.
Please tell me what you think.
Sorry, I took a few days off, I will look at your project later today...
I see nothing wrong with your code. The WSDL does not specify any SOAP header (which would be useful) and as far as my tests show for example with ASP.NET sessions (that also require a cookie from the server to the client that gets returned with each follow-up request), the Delphi Win32 clients support cookie handling out-of-the-box.

I wonder if the problem is at the server side. Looking at the WSDL, there are some aspects that make me wonder about the server implementation. Seeing namespaces with tempuri.org only increases that feeling. I would see if they can modify the server to use SOAP headers, use a correct namespace, etc.
Since this goes nowhere... my code should work as it is... and I want to give you points... please help me with another problem in the same area.
I have 2 links. One is a WSDL and the other is an XSD. The problem is that the XSD contains declarations that are used by the WSDL, and the WSDL does not work correctly with xsd:import.
My conclusion is that the XSD contents should somehow be merged with the WSDL. So the first steps are to save the contents of both links (WSDL + XSD) in 2 local files with appropriate extensions. And then the xsd contents should somehow be added to the WSDL. Since Delphi's WSDL importer wizard apparently does not work well with xsd:import, instead of the reference to the import... there probably should be directly the contents of the xsd...
Here are the links. Please merge them correctly because I have no idea how to do it properly (and I'll give you the points):

https://www.omniasigonline.ro/portalAsiguratori/QuotationService?wsdl   
https://www.omniasigonline.ro/portalAsiguratori/QuotationService?xsd=1
I saved the first WSDL URL as QuotationService.wsdl and the second as QuotationService.xsd, and then only had to edit QuotationService.wsdl and change schemaLocation="QuotationService.xsd"

The two files plus the import unit (by the WSDLIMP for Delphi 2010) are attached. The .wsdl file is renamed to .xml, otherwise I was not allowed to upload it.
QuotationService.zip
ASKER CERTIFIED SOLUTION
Avatar of ebob42
ebob42
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will definitely buy your publication.
Thanks a lot. I never would have thought to replace the path of the SchemaLocation. I always thought of something complicated with XML syntax.
So the solution is brilliant.
You deserve all the points. Too bad I do not have more points to raise them a little.

Thank you
Brilliant