如果您有不同位置的相同服务,只需使用“添加服务引用...”添加它并在服务客户端构造函数中添加指定的 URL:
var svc = new DataServiceClient("BasicHttpBinding_DataService",
"http://url.com/DataService.svc");
BasicHttpBinding_DataService
是来自客户端配置的(生成的)绑定名称(在执行“添加新的 Web 引用...”时自动生成):
例子ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_DataService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:44300/Services/DataService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataService"
contract="DataService.DataService" name="BasicHttpBinding_DataService" />
</client>
</system.serviceModel>
</configuration>
上面的代码可用于将地址(例如https://localhost:44300/Services/DataService.svc
)更改为运行时生成的地址...
看看这个:http ://blog.rsuter.com/?p=281