2011-12-18 1 views
1

ClientCredentialType을 'None'으로 설정하여 압축 및 메시지 보안을 사용하여 사용자 지정 WS 바인딩을 구현하려고합니다. 서비스가 구성되어 성공적으로 실행 중입니다. 또한 클라이언트를 구성하고 성공적으로 실행했습니다. 그러나 프로그래밍 방식으로 클라이언트를 설정해야하므로 클라이언트 구성을 코드로 변환하려고 할 때 '오류가 발생합니다. 대상'xxx '에 대한 서비스 인증서가 제공되지 않습니다. ClientCredentials에 서비스 인증서를 지정하십시오. ' 자동 생성 된 프록시 클라이언트를 사용하고 있으며 클라이언트 생성자를 재정의하고 클라이언트 인증서 또는 클라이언트 끝점 동작에 직접 서비스 인증서 CertificateValidationMode을 지정하는 권장 사항을 따라 왔지만 여전히 행운은 없습니다.사용자 지정 WS 바인딩 오류 : 대상 'xxx'에 대한 서비스 인증서가 제공되지 않습니다. 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); 
} 
+0

가능한 복제본 http://stackoverflow.com/questions/4441072/the-service-certificate-is-not-provided-for-target-specify-a-service-certi –

답변

관련 문제