开发者

How to chose the IP of the service reference in C#?

开发者 https://www.devze.com 2023-02-14 15:04 出处:网络
I have a simple console application and a WCF service, which are already connected and functiona开发者_如何学JAVAl, but now I want to know how to make my application connect to this same web service,

I have a simple console application and a WCF service, which are already connected and functiona开发者_如何学JAVAl, but now I want to know how to make my application connect to this same web service, but hosted somewhere else? The idea is to have several instances of the application that connects to the web service, but they might be connected in other servers. Is there a way to do this without having to compile the same software several times?


You can set the service client's Endpoint.Address to a new address (code stolen from http://bytes.com/topic/net/answers/696769-change-wcf-client-endpoint-address):

HelloWorld.HelloWorldClient client = new WCFHelloWorldClient.HelloWorld.HelloWorldClient();

//change the endpointAddress here client.Endpoint.Address = new EndpointAddress("http://localhost:8899/BasicHost/HelloWorld");

You can also set address in the client's constructor, but that will make you to also enter the configuration name which I think is a bit messy.

A similar question (with answer) is also found here: How can I change the address of a WCF service reference? .


Read up on WCF Client configuration.

Everything can be done in .config files which you can just post around, and/or programmatically if you need it to be even more dynamic

http://msdn.microsoft.com/en-us/library/ms731745.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消