读书人

怎么动态指定EndPoint Address

发布时间: 2012-03-22 17:43:57 作者: rapoo

如何动态指定EndPoint Address
在开发时用的<endpoint address="http://localhost:4951/...
怎么让他在发布后能够成功调试

[解决办法]
string host=HtmlPage.Document.DocumentUri.Host;
client.Endpoint.Address = new System.ServiceModel.EndpointAddress(new Uri(string.Format("http://{0}:8731/LoginService", host)));
//8731端口号,LoginService服务名
[解决办法]
VS在生成代理类时,会自动生成5个构造函数,

C# code
public XXXClient() {}public XXXClient(string endpointConfigurationName) :         base(endpointConfigurationName) {}public XXXClient(string endpointConfigurationName, string remoteAddress) :         base(endpointConfigurationName, remoteAddress) {}public XXXClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :         base(endpointConfigurationName, remoteAddress) {}public XXXClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :         base(binding, remoteAddress) {}
[解决办法]
在客户端添加引用后,在ServiceReferences.ClientConfig 中会自动生成绑定信息和EndPoint信息。

你也可以在代码中定义EndPointAddress,可以参考下面的代码:


VB.NET code
Dim binding As BasicHttpBinding = New BasicHttpBinding()Dim address As New EndpointAddress(New Uri(Application.Current.Host.Source, "你的SVC地址"))Dim client As New DataServiceClient(binding, address)AddHandler client.GetValuesCompleted, AddressOf client_GetValuesCompleted        client.GetValuesAsync(ID)... 

读书人网 >CAD教程

热点推荐