Question

I'm writing an application which consumes SOAP services to send data. The user can change the url endpoint in application settings.

Here's what I do :

public HubHandler()
{
    this.urlHub = Settings.Default.UrlWebService;
    //some code
    this.connect();
}


private void connect()
{
    this.service = new HubService();
    this.service.Proxy = System.Net.HttpWebRequest.GetSystemWebProxy();
    this.service.Proxy.Credentials = CredentialCache.DefaultCredentials;
    this.service.Url = this.urlHub;
}

Actually I just change the service's Url attribute, from what I read it must be enough to do what I want.

When the url configured by user is the same than the one i put by default in web reference properties, everything is OK. But when the user enters his own URL, an exception is thrown as soon as a service method is called (here authenticate) :

Unable to cast object of type 'System.Xml.XmlNode[]' to type 'HubServiceAuthenticateOut'

and

There is an error in XML document (2, 649)

I captured packets with Wireshark and compared both situations : content is exactly the same, just the namespace changes with url. XML is perfectly correct (Server side, it's a php app with zend soap autodiscover which generates wsdl and handles calls).

Does anyone has already encoutered this kind of issue ? Is there a better way to change service endpoint than url attribute ?

When I look in my Reference.cs, I see namespace hard coded, like that :

[System.Web.Services.WebServiceBindingAttribute(Name="HubServiceBinding", Namespace="https://localhost/myapp/HubService.php")]

Even if url attribute is dynamic, could it be related ?

Thanks !

Was it helpful?

Solution

Finally it seems impossible to do what I want. The thing is that the framework parses webservice responses and checks namespaces.

Have a look at this post : Webservice fails to cast type using dynamic URL: There is an error in XML document (2, 691)

We can define 3 cases :

  1. Only one endpoint, no problem
  2. Finite number of endpoints : 1 Web Reference per domain. Read this, interesting answer, gives a good idea on how to manage this programmatically : https://stackoverflow.com/a/18322644/2806497
  3. Infinite number of endpoints : No way to handle it with visual studio webreferences.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top