.NET is quite great to create and publish your own web services, and an eventually a client for it, almost without typing anything.
How to give your client the capacity to choose which server to connect to, in case of a distributed web service ?
When you create your web service in Visual studio, it asks you for the address of the service in order to generate the Service Reference, and then writes this address into the config file.
So, how to dynamically change the address of the targeted web service ?
//We set the server's new address string server_address = "http://www.newaddress.com:80"; ServiceName.ServiceReferenceSoapClient server = new ServiceName.ServiceReferenceSoapClient(); System.ServiceModel.EndpointAddress addr = new System.ServiceModel.EndpointAddress(server_address); server.Endpoint.Address = addr; Uri site = new Uri(server_address); server.Endpoint.ListenUri = site; //Then use the server as usual : server.HelloWorld();
Commentaires
Ecrire un commentaire Trackback