title: What WS-Security settings should I apply to connect to wsdl descripted SOAP service?
body: <p>I've been given task to create java client for a specific web service that is described by following wsdl file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Person" targetNamespace="http://tempuri.org/"&gt;
    &lt;wsp:Policy wsu:Id="WSHttpBinding_IPersonService_policy"&gt;
      &lt;wsp:ExactlyOne&gt;
        &lt;wsp:All&gt;
          &lt;sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
            &lt;wsp:Policy&gt;
              &lt;sp:TransportToken&gt;
                &lt;wsp:Policy&gt;
                  &lt;sp:HttpsToken RequireClientCertificate="false" /&gt;
                &lt;/wsp:Policy&gt;
              &lt;/sp:TransportToken&gt;
              &lt;sp:AlgorithmSuite&gt;
                &lt;wsp:Policy&gt;
                  &lt;sp:Basic256 /&gt;
                &lt;/wsp:Policy&gt;
              &lt;/sp:AlgorithmSuite&gt;
              &lt;sp:Layout&gt;
                &lt;wsp:Policy&gt;
                  &lt;sp:Strict /&gt;
                &lt;/wsp:Policy&gt;
              &lt;/sp:Layout&gt;
              &lt;sp:IncludeTimestamp /&gt;
            &lt;/wsp:Policy&gt;
          &lt;/sp:TransportBinding&gt;
          &lt;sp:EndorsingSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
            &lt;wsp:Policy&gt;
              &lt;sp:SecureConversationToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"&gt;
                &lt;wsp:Policy&gt;
                  &lt;sp:BootstrapPolicy&gt;
                    &lt;wsp:Policy&gt;
                      &lt;sp:SignedParts&gt;
                        &lt;sp:Body /&gt;
                        &lt;sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing" /&gt;
                        &lt;sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing" /&gt;
                        &lt;sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" /&gt;
                        &lt;sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing" /&gt;
                        &lt;sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing" /&gt;
                        &lt;sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing" /&gt;
                        &lt;sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing" /&gt;
                      &lt;/sp:SignedParts&gt;
                      &lt;sp:EncryptedParts&gt;
                        &lt;sp:Body /&gt;
                      &lt;/sp:EncryptedParts&gt;
                      &lt;sp:TransportBinding&gt;
                        &lt;wsp:Policy&gt;
                          &lt;sp:TransportToken&gt;
                            &lt;wsp:Policy&gt;
                              &lt;sp:HttpsToken RequireClientCertificate="false" /&gt;
                            &lt;/wsp:Policy&gt;
                          &lt;/sp:TransportToken&gt;
                          &lt;sp:AlgorithmSuite&gt;
                            &lt;wsp:Policy&gt;
                              &lt;sp:Basic256 /&gt;
                            &lt;/wsp:Policy&gt;
                          &lt;/sp:AlgorithmSuite&gt;
                          &lt;sp:Layout&gt;
                            &lt;wsp:Policy&gt;
                              &lt;sp:Strict /&gt;
                            &lt;/wsp:Policy&gt;
                          &lt;/sp:Layout&gt;
                          &lt;sp:IncludeTimestamp /&gt;
                        &lt;/wsp:Policy&gt;
                      &lt;/sp:TransportBinding&gt;
                      &lt;sp:SignedSupportingTokens&gt;
                        &lt;wsp:Policy&gt;
                          &lt;sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"&gt;
                            &lt;wsp:Policy&gt;
                              &lt;sp:WssUsernameToken10 /&gt;
                            &lt;/wsp:Policy&gt;
                          &lt;/sp:UsernameToken&gt;
                        &lt;/wsp:Policy&gt;
                      &lt;/sp:SignedSupportingTokens&gt;
                      &lt;sp:Wss11&gt;
                        &lt;wsp:Policy /&gt;
                      &lt;/sp:Wss11&gt;
                      &lt;sp:Trust10&gt;
                        &lt;wsp:Policy&gt;
                          &lt;sp:MustSupportIssuedTokens /&gt;
                          &lt;sp:RequireClientEntropy /&gt;
                          &lt;sp:RequireServerEntropy /&gt;
                        &lt;/wsp:Policy&gt;
                      &lt;/sp:Trust10&gt;
                    &lt;/wsp:Policy&gt;
                  &lt;/sp:BootstrapPolicy&gt;
                &lt;/wsp:Policy&gt;
              &lt;/sp:SecureConversationToken&gt;
            &lt;/wsp:Policy&gt;
          &lt;/sp:EndorsingSupportingTokens&gt;
          &lt;sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
            &lt;wsp:Policy /&gt;
          &lt;/sp:Wss11&gt;
          &lt;sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
            &lt;wsp:Policy&gt;
              &lt;sp:MustSupportIssuedTokens /&gt;
              &lt;sp:RequireClientEntropy /&gt;
              &lt;sp:RequireServerEntropy /&gt;
            &lt;/wsp:Policy&gt;
          &lt;/sp:Trust10&gt;
          &lt;wsaw:UsingAddressing /&gt;
        &lt;/wsp:All&gt;
      &lt;/wsp:ExactlyOne&gt;
    &lt;/wsp:Policy&gt;
    &lt;wsdl:types&gt;
      &lt;xsd:schema targetNamespace="http://tempuri.org/Imports"&gt;
        &lt;xsd:import schemaLocation="https://localhost:442/Services/Person.svc?xsd=xsd0" namespace="http://tempuri.org/" /&gt;
        &lt;xsd:import schemaLocation="https://localhost:442/Services/Person.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" /&gt;
      &lt;/xsd:schema&gt;
    &lt;/wsdl:types&gt;
    &lt;wsdl:message name="IPersonService_GetSomething_InputMessage"&gt;
      &lt;wsdl:part name="parameters" element="tns:GetSomething" /&gt;
    &lt;/wsdl:message&gt;
    &lt;wsdl:message name="IPersonService_GetSomething_OutputMessage"&gt;
      &lt;wsdl:part name="parameters" element="tns:GetSomethingResponse" /&gt;
    &lt;/wsdl:message&gt;
    &lt;wsdl:portType name="IPersonService"&gt;
      &lt;wsdl:operation name="GetSomething"&gt;
        &lt;wsdl:input wsaw:Action="http://tempuri.org/IPersonService/GetSomething" message="tns:IPersonService_GetSomething_InputMessage" /&gt;
        &lt;wsdl:output wsaw:Action="http://tempuri.org/IPersonService/GetSomethingResponse" message="tns:IPersonService_GetSomething_OutputMessage" /&gt;
      &lt;/wsdl:operation&gt;
    &lt;/wsdl:portType&gt;
    &lt;wsdl:binding name="WSHttpBinding_IPersonService" type="tns:IPersonService"&gt;
      &lt;wsp:PolicyReference URI="#WSHttpBinding_IPersonService_policy" /&gt;
      &lt;soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /&gt;
      &lt;wsdl:operation name="GetSomething"&gt;
        &lt;soap12:operation soapAction="http://tempuri.org/IPersonService/GetSomething" style="document" /&gt;
        &lt;wsdl:input&gt;
          &lt;soap12:body use="literal" /&gt;
        &lt;/wsdl:input&gt;
        &lt;wsdl:output&gt;
          &lt;soap12:body use="literal" /&gt;
        &lt;/wsdl:output&gt;
      &lt;/wsdl:operation&gt;
    &lt;/wsdl:binding&gt;
    &lt;wsdl:service name="Person"&gt;
      &lt;wsdl:port name="WSHttpBinding_IPersonService" binding="tns:WSHttpBinding_IPersonService"&gt;
        &lt;soap12:address location="https://localhost:442/Services/Person.svc" /&gt;
        &lt;wsa10:EndpointReference&gt;
          &lt;wsa10:Address&gt;https://localhost:442/Services/Person.svc&lt;/wsa10:Address&gt;
        &lt;/wsa10:EndpointReference&gt;
      &lt;/wsdl:port&gt;
    &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>I've created java client with Apache CXF's wsdl2java and in client invocation used <code>new AddressingFeature(true)</code>, because services are in HTTPS, like that:</p>
  
  <pre><code>Person p = new Person();
  IPersonService iPersonService = p.getWSHttpBindingIPersonService(new AddressingFeature(true));
  System.out.println(iPersonService.getSomething());
  </code></pre>
  
  <p>but I get following exception:</p>
  
  <blockquote>
    <p>org.apache.cxf.binding.soap.SoapFault: The message could not be processed. This is most likely because the action '<a href="http://tempuri.org/IPersonService/GetSomething" rel="nofollow">http://tempuri.org/IPersonService/GetSomething</a>' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding. </p>
  </blockquote>
  
  <p>So far, I've tried adding <code>ws-security.username</code> and <code>ws-security.password</code> like so, but it didn't work, I get the same exception:</p>
  
  <pre><code>((BindingProvider) iPersonService).getRequestContext() 
     .put("ws-security.username", "user"); 
  ((BindingProvider) iPersonService).getRequestContext() 
     .put("ws-security.password", "password"); 
  </code></pre>
  
  <p>So, most probably I didn't applied some kind of security settings. Can anybody describe what WS-Security settings should I apply for this specific wsdl? </p>
  
  <p>Update:<br>
  Added xsd schemas: <a href="https://gist.github.com/the-lay/12c2dc5091c5dc783f00" rel="nofollow">https://gist.github.com/the-lay/12c2dc5091c5dc783f00</a></p>