I have 4 portals (WW, EU, AU, US), every one of them has its own web service (through PHP which means I do not have control over).
For those 4 web services, I have 4 clients (generated by VS.Net Add Web Reference).
There is a method called CommonMethod
it is the same on all web services, returns an object of type CommonClass
.
There is an error in XML document (2, 615).
, and the InnerException says "Cannot assign object of type NS.com.AU.CommonClass to an object of type NS.com.EU.CommonClass.".There is an error in XML document (2, 615).
, and the InnerException says "Cannot assign object of type NS.com.AU.CommonClass to an object of type NS.com.US.CommonClass.".There is an error in XML document (2, 615).
, and the InnerException says "Cannot assign object of type NS.com.AU.CommonClass to an object of type NS.com.WW.CommonClass.".I searched the web for such error, well it is XML so a lot of irrelevant stuff comes up and could not find something useful.
Now I noticed, the 4 web services are using the same namespace in their WSDL documents (xmlns:tns="urn:rambo.com:RamboComApi"). Can this be the source of confusion and type-casting exception? Should I tell the authors of the web services to choose different namespace for each web service?
The web services might be identical, but they are not the same. That is, it is not like that the same PHP code is hosted at all the places. the PHP service code might be maintained separately. what this means is that you must have four clients in your code. 4 service references. That you are doing very well.
now, you can use one client to connect only to its own server. so use EU client to connect to EU. use US client to connect to US. here by client i mean proxy (the thing add-service-ref generates)
The consumer code might want to consume services irrespective of their location. for that i recommend using Adapter Pattern. so it would be something like this:
your code:
IServiceAdapter adapter = ServiceFactory.createAdapter("EU");
adapter.DoStuff();
...
IServiceAdapter AdapterFactory
--------------- --------------
void DoStuff1(); IServiceAdapter CreateAdapter(string Target) {
int DoStuff2(); switch Target {
case "EU"
return new EUServiceAdapter();
break;
case "US"
return new USServiceAdapter();
break;
}
}
EU_ServiceAdpater
-----------------------
(Implement IServiceAdapter)
void DoStuff1() {
ServiceReference_EU.ServiceObject1.DoStuff1();
}
int DoStuff2() {
return ServiceReference_EU.ServiceObject1.DoStuff2();
}
US_ServiceAdpater
-----------------------
(Implement IServiceAdapter)
void DoStuff1() {
ServiceReference_US.ServiceObject1.DoStuff1();
}
int DoStuff2() {
return ServiceReference_US.ServiceObject1.DoStuff2();
}
in this way, your client code will be shielded from the actual endpoints. As an alternate approach you can reconfigure the endpoints directly though in-code-configuration of teh service client, but i wont recommend that. It breaks the moment when the EU guy decides to make a little change which US guy did not. best, go for adapter pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With