2011-10-27 6 views
0

私はクライアント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; 
} 

実行時に契約値を設定するにはどうすればよいですか?

はあなたがEndpointAddressとの契約を関連付けない

答えて

1

、あなたはServiceEndpointに関連付けありがとう。そして今度は、あなたはまた、次のようにServiceEndpointであなたのEndpointAddressを関連付ける:

host.AddServiceEndpoint(httpEndpoint); 

ServiceEndpoint httpEndpoint = new ServiceEndpoint 
(
    ContractDescription.GetContract(
     typeof(Project.Services.Contract.IMyContract), 
     typeof(Project.Services.MyContract)), 
    new WSHttpBinding { ... }, 
    GetEndpoint(serverAddress, serviceName) 
); 

は最終的には、ServiceHostに追加すべきことであるが、ServiceEndpointのこのインスタンスであります

関連する問題