我在客户端app.config中有以下内容。
<client>
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration="SecureBinding"
contract="Project.Services.Contract.IMyContract" name="Endpoint_Default">
<identity>
<servicePrincipalName value="host/mikev-ws" />
</identity>
</endpoint>
</client>
我有以下代码在运行时设置端点。
private EndpointAddress GetEndpoint(string serverAddress, string serviceName)
{
string endpointURL = string.Format("http://{0}/Services/{1}.svc"
, serverAddress, serviceName);
EndpointIdentity spn = EndpointIdentity.CreateSpnIdentity("host/mikev-ws");
Uri uri = new Uri(endpointURL);
EndpointAddress endpoint = new EndpointAddress(uri, spn);
return endpoint;
}
如何在运行时设置合约价值?
谢谢
答案 0 :(得分:1)
您不会将合同与EndpointAddress
相关联,而是将其与ServiceEndpoint
相关联。反过来,您还会将EndpointAddress
与ServiceEndpoint
关联,如下所示:
ServiceEndpoint httpEndpoint = new ServiceEndpoint
(
ContractDescription.GetContract(
typeof(Project.Services.Contract.IMyContract),
typeof(Project.Services.MyContract)),
new WSHttpBinding { ... },
GetEndpoint(serverAddress, serviceName)
);
最终,ServiceEndpoint
的这个实例应添加到ServiceHost
:
host.AddServiceEndpoint(httpEndpoint);