title: Custom Binding consuming a weblogic webservice ws-security 1.2
body: <p>I'm trying to consume a WebLogic webservice with ws-security 1.2. </p>
  
  <p>In the WSDL, the security section is the following:</p>
  
  <pre><code>&lt;wsp:UsingPolicy wssutil:Required="true"/&gt;
  &lt;wsp1_2:Policy wssutil:Id="Wssp1.2-2007-SignBody.xml"&gt;
  &lt;ns1:SignedParts xmlns:ns1="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"&gt;
  &lt;ns1:Body/&gt;
  &lt;/ns1:SignedParts&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;wsp1_2:Policy wssutil:Id="Wssp1.2-2007-Wss1.0-X509-Basic256.xml"&gt;
  &lt;ns2:AsymmetricBinding xmlns:ns2="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns2:InitiatorToken&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns2:X509Token ns2:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns2:WssX509V3Token10/&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns2:X509Token&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns2:InitiatorToken&gt;
  &lt;ns2:RecipientToken&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns2:X509Token ns2:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never"&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns2:WssX509V3Token10/&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns2:X509Token&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns2:RecipientToken&gt;
  &lt;ns2:AlgorithmSuite&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns2:Basic256/&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns2:AlgorithmSuite&gt;
  &lt;ns2:Layout&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns2:Lax/&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns2:Layout&gt;
  &lt;ns2:IncludeTimestamp/&gt;
  &lt;ns2:ProtectTokens/&gt;
  &lt;ns2:OnlySignEntireHeadersAndBody/&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns2:AsymmetricBinding&gt;
  &lt;ns3:Wss10 xmlns:ns3="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"&gt;
  &lt;wsp1_2:Policy&gt;
  &lt;ns3:MustSupportRefKeyIdentifier/&gt;
  &lt;ns3:MustSupportRefIssuerSerial/&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;/ns3:Wss10&gt;
  &lt;/wsp1_2:Policy&gt;
  &lt;wsp:Policy wssutil:Id="Wssp1.2-2007-Wsp1.5-EncryptBody.xml"&gt;
  &lt;ns4:EncryptedParts xmlns:ns4="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"&gt;
  &lt;ns4:Body/&gt;
  &lt;/ns4:EncryptedParts&gt;
  &lt;/wsp:Policy&gt;
  </code></pre>
  
  <p>After a lot of search because I'm new in wcf I ended up into the following configuration:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;client&gt;
      &lt;endpoint name="wssMutualCert_Client"
       address="https://..."
       binding="customBinding"
       bindingConfiguration="custom1"
       contract="MyWebService.WebServicesMainMethod"
       behaviorConfiguration="MutualCertBehavior"&gt;
      &lt;/endpoint&gt;
  &lt;/client&gt;
  &lt;bindings&gt;
      &lt;customBinding&gt;
          &lt;binding name="custom1" closeTimeout="00:01:00"
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"&gt;
  
              &lt;textMessageEncoding messageVersion="Soap11" writeEncoding="UTF-8" /&gt;
              &lt;security defaultAlgorithmSuite="Basic256"
                        authenticationMode="MutualCertificateDuplex"
                        includeTimestamp="True" 
                        messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" 
                        securityHeaderLayout="LaxTimestampLast" messageProtectionOrder="SignBeforeEncrypt"&gt;
                  &lt;localClientSettings maxClockSkew="00:07:00" /&gt;
                  &lt;localServiceSettings maxClockSkew="00:07:00" /&gt;
                  &lt;secureConversationBootstrap&gt;
                      &lt;localClientSettings maxClockSkew="00:07:00" /&gt;
                      &lt;localServiceSettings maxClockSkew="00:07:00" /&gt;
                  &lt;/secureConversationBootstrap&gt;
              &lt;/security&gt;
              &lt;context protectionLevel="EncryptAndSign"/&gt;
              &lt;httpsTransport requireClientCertificate="true" maxBufferPoolSize="20000000" maxBufferSize="20000000" maxReceivedMessageSize="20000000"/&gt;
          &lt;/binding&gt;
  
      &lt;/customBinding&gt;
      &lt;ws2007HttpBinding&gt;
          &lt;binding name="wssMutualCertBinding"&gt;
              &lt;security mode="TransportWithMessageCredential"&gt;
                  &lt;message clientCredentialType="Certificate"/&gt;
                  &lt;transport clientCredentialType="Certificate"/&gt;
              &lt;/security&gt;
          &lt;/binding&gt;
      &lt;/ws2007HttpBinding&gt;
  &lt;/bindings&gt;
  &lt;behaviors&gt;
      &lt;endpointBehaviors&gt;
          &lt;behavior name="MutualCertBehavior"&gt;
              &lt;clientCredentials&gt;
                  &lt;serviceCertificate&gt;
                      &lt;defaultCertificate
                        findValue="XXXXX"
                        storeLocation="LocalMachine"
                        storeName="TrustedPeople" x509FindType="FindByThumbprint"/&gt;
                  &lt;/serviceCertificate&gt;
                  &lt;clientCertificate
                      findValue="YYYYY"
                      storeLocation="LocalMachine"
                      storeName="TrustedPeople" x509FindType="FindByThumbprint"/&gt;
              &lt;/clientCredentials&gt;
          &lt;/behavior&gt;
      &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;system.serviceModel&gt;
  </code></pre>
  
  <p>My test appl looks like following:</p>
  
  <pre><code>static void Main(string[] args)
  {
      MyWebService.WebServicesMainMethodClient client = new WebServicesMainMethodClient("wssMutualCert_Client");
      MyWebService.webRequest request = new webRequest();
      ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
  
      try
      {
          webResponse response = client.retrieve(request);
      }
      catch (Exception e)
      {
          throw e;
      }
  }
  public static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  {
      return true;
  }
  </code></pre>
  
  <p>And what ever change I try in my configuration I receive the following:</p>
  
  <pre><code>An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail. 
  
  Server stack trace: 
     at     System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply      (Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
  at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request      (Message message, TimeSpan timeout)
     at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message,     TimeSpan timeout)
      at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,      ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,      ProxyOperationRuntime operation, Object[] ins, Object[] outs)
     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService    (IMethodCallMessage methodCall, ProxyOperationRuntime operation)
     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
  Exception rethrown at [0]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
     at Client.MyWebService.WebServicesMainMethod.retrieve(retrieve request)
  </code></pre>
  
  <p>I have been trying to find something helpfull almost 2 days now. I've searhed time sychonization issues, certs issues.
  <strong>ANY IDEA OR RECOMMENDATION WOULD BE VERY HELPFULL.</strong>
  Thank you all in advance.</p>