tags:

views:

496

answers:

3

Okay, simple situation: I'm writing a simple console application which connects to a SOAP web service. I've imported a SOAP Service reference and as a result, my application has a default endpoint build into it's app.config file.

The web service, however, can run on multiple servers and the URL to the proper web service is passed through the commandline parameters of my application. I can read the URL, but how do I connect the web service to this custom URL?

(It should be very simple, in my opinion. It's something I'm overlooking.)

+2  A: 

Is this using an auto-generated class deriving from SoapHttpClientProtocol? If so, just set the Url property when you create an instance of the class.

Jon Skeet
I've right-clicked references, selected "Add Service Reference..." and poof! Auto-code. It's not derived from SoapHttpClientProtocol, as far as I can see.
Workshop Alex
Okay, so that's using WCF I suspect, which means it'll be a different property.
Jon Skeet
Actually, it's just calling the constructor of the SOAP class with the name of the binding and the custom URL. The name of the binding can be found in the app.config where the SOAP endpoint is defined.
Workshop Alex
+2  A: 

As Jon said, you set the Url, as in:

Namespace.ClassName nwe = new Namespace.ClassName();
nwe.Url = "http://localhost/MyURL/site.asmx";
Pete OHanlon
Useful information. However, the error was server-side. :-)
Workshop Alex
Could you explain the comment? It's not very clear.
Jon Skeet
(In particular, if you were experiencing an error on the server it would have been nice if you'd mentioned that in the question. Currently the question looks as if it's just asking how to configure the *client* to talk to a different URL...)
Jon Skeet
The comment is clear to me, since it tells one way to set a custom URL. It's just that I originally used a slightly different technique.About the server error. I did not notice it until after I've changed the way in which I called the web service.
Workshop Alex
+1  A: 

Well, .NET can provide some very useless error messages sometimes. In IIS, the service was configured to AutoDetect cookieless mode. As a result, I had to append "?AspxAutoDetectCookieSupport=1" to the URL. Although that would fix the problem, it was just easier to go to the IIS console, open the properties of the service, go to the ASP.NET tab page, click the "Edit configuration" button, to to "State Management" in the newly popped up screen and change "Cookieless mode" into something other than "AutoDetect"...

Excuse me. Dumb error. Am going to hit myself on the head a few times for this. ;-)

Workshop Alex
We all make these mistakes, and this is no dumber than some of the whoppers I've made. ;->
Pete OHanlon