2
votes

I have added a service reference in my project.

I need to pass in the security header as per below

<soapenv:Header>
  <oas:Security>
      <oas:UsernameToken>
        <oas:Username>username</oas:Username>
        <oas:Password>!password</oas:Password>
     </oas:UsernameToken>
  </oas:Security>

How do i set this. If you look at how I set the request, is it possible to do the same somehow with the headers.

The security xsds are embedded in the WSDL.

http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd

and

http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd.

The request to the service operation is populated as per below:

MyWebService.PortTypeClient client = new MyWebService.PortTypeClient();

MyWebService.SecurityHeaderType secHeader = new MyWebService.SecurityHeaderType();    

RetrieveOperationRequest detailsRequest = new RetrieveOperationRequest ();
detailsRequest.inputParam1 = "1234";

var result = client.RetrieveOperation(secHeader, detailsRequest);

How do i generate the Header part???

You can see i pass security header as this is required by the web service.

Thanks.

1

1 Answers

1
votes

I managed to find the solution/workaround.

This is set in the Web.config file.

 <client>
  <endpoint address="http://localhost:6478/service/1.0"
    binding="basicHttpBinding" bindingConfiguration="ServiceEndpointBinding"
    contract="TestService.PortType" name="ServiceEndpoint">
    <headers>
      <ns2:Security xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
        xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <ns2:UsernameToken>
          <ns2:Username>username</ns2:Username>
          <ns2:Password>!password</ns2:Password>
        </ns2:UsernameToken>
      </ns2:Security>
    </headers>
  </endpoint>
</client>

Unfortunatly I cannot find the source for this solution anymore. I am just resolving this Question.