Dynamic web service proxy in .NET?
I need to implement a system that has the ability to conditionally consume web services on different disparate applications which are deployed with the same WSDL.
For e.g., If System B, C, D and E host webservices WS1, WS2, WS3 and WS4 which are all based on the same WSDL thereby exposing the same web methods, then my system A would require to consume one of these 4 webservices based on a condition retrieved from a downstream component (e.g., the database). The systems B, C, D and E can be implemented in any technology (Java, .NET, etc..) but my system A is based on .NET.
So the proxy class based on this WSDL on my system A would need to dynamically change the URI in the webservice proxy. So how do I dynamically change the endpoint before I cons开发者_运维百科ume the required webservice?
The proxy class generated by "Add Service Reference" or svcutil.exe has several constructors that accept a remote address. Use one of those. See WCF Client Overview.
For instance:
EndpointAddress addr = new EndpointAddress(uri);
var client = new MyServiceClient(bindingConfigurationName, addr);
Do you mean change the url like this?
net.webservicex.www.LondonGoldAndSilverFix Proxy = new net.webservicex.www.LondonGoldAndSilverFix();
Proxy.Url = "http://www.webservicex.net/LondonGoldFix.asmx";
精彩评论