ClientCredentialType を「None」に設定して、圧縮とメッセージ セキュリティを備えたカスタム WS バインディングを実装しようとしています。サービスが構成され、正常に実行されています。また、クライアントを構成して正常に実行することもできました。ただし、クライアントをプログラムでセットアップする必要があるため、クライアント構成をコードに変換しようとすると、「サービス証明書がターゲット 'xxx' に提供されていません。ClientCredentials でサービス証明書を指定してください。自動生成されたプロキシ クライアントを使用しています。クライアント コンストラクターをオーバーライドし、サービス証明書CertificateValidationModeを ClientCredentials またはクライアント エンドポイントの動作で直接指定するという推奨事項に従いましたが、それでもうまくいきません。
これを解決するための助けをいただければ幸いです。参考までに、構成とそのコード翻訳を以下に含めます。
クライアント構成:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="customWSBinding" sendTimeout="00:15:00">
<security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<secureConversationBootstrap authenticationMode="AnonymousForSslNegotiated" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
</security>
<gzipMessageEncoding innerMessageEncoding="textMessageEncoding"/>
<httpTransport hostNameComparisonMode="StrongWildcard" manualAddressing="False"
maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
authenticationScheme="Anonymous" bypassProxyOnLocal="False" realm="" useDefaultWebProxy="True"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address=""
binding="customBinding"
bindingConfiguration="customWSBinding"
behaviorConfiguration="ClientBehavior"
contract="IService"
name="ServiceEndpoint">
<identity>
<dns value="contoso.com"/>
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ClientBehavior">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
同等のコード:
SecurityBindingElement securityElement = SecurityBindingElement.CreateSecureConversationBindingElement(SecurityBindingElement.CreateAnonymousForCertificateBindingElement());
securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
GZipMessageEncodingBindingElement encodingElement = new GZipMessageEncodingBindingElement();
TextMessageEncodingBindingElement txtMsgBE = new TextMessageEncodingBindingElement();
encodingElement.InnerMessageEncodingBindingElement = txtMsgBE;
HttpTransportBindingElement httpTransportElement = new HttpTransportBindingElement();
httpTransportElement.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
httpTransportElement.ManualAddressing = false;
httpTransportElement.MaxReceivedMessageSize = Int32.MaxValue;
httpTransportElement.MaxBufferSize = Int32.MaxValue;
httpTransportElement.MaxBufferPoolSize = Int32.MaxValue;
httpTransportElement.AuthenticationScheme = AuthenticationSchemes.Anonymous;
httpTransportElement.BypassProxyOnLocal = false;
httpTransportElement.UseDefaultWebProxy = true;
System.ServiceModel.Channels.Binding binding = new CustomBinding(securityElement, encodingElement, httpTransportElement);
binding.SendTimeout = TimeSpan.FromMinutes(15);
EndpointAddress address = new EndpointAddress(new Uri(svcURL), EndpointIdentity.CreateDnsIdentity("contoso.com"));
ServiceClient svcClient = new ServiceClient(binding, address);
オーバーライドされたプロキシ クライアント:
public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress)
:base (binding, remoteAddress)
{
System.ServiceModel.Description.ClientCredentials cc = new System.ServiceModel.Description.ClientCredentials();
cc.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
base.Endpoint.Behaviors.RemoveAt(1);
base.Endpoint.Behaviors.Add(cc);
}