是否可以在客户端的新端口上重新启动WCF Web服务? 我是否需要在服务器端更改硬编码的baseUrl,以便可以在客户端更改它?还是我需要在客户端更改Endpoints(config)?
这是我现在使用的代码: WCF配置文件:
<service name="WcfService.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://MYIPADDRESS:8000/myService/" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="WcfService.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
客户端: 配置文件:
<client>
<endpoint address="http://MYIPADDRESS:8000/myService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService11"
contract="Proxy1.IService1" name="ServicePort8000" />
</client>
所以我要做的是在客户端自行设置端口:
Proxy1.Service1Client test = new Proxy1.Service1Client("ServicePort8000");
String http = test.Endpoint.Address.Uri.Scheme.ToString();
String host = test.Endpoint.Address.Uri.Host.ToString();
String port = txtServerPort.Text;
String localPath = test.Endpoint.Address.Uri.LocalPath.ToString();
String adress = http + "://" + host + ":" + port + localPath;
test.Endpoint.Address = new EndpointAddress(adress);
但这不是方法。 有可能吗?