Link to home
Start Free TrialLog in
Avatar of jefersonsv
jefersonsvFlag for Brazil

asked on

How to add SOAP HEADER SECURITY in C# WCF 3.5 (http)

I need add <soapenv:Header> with my credential (simple text over http)

Below is a example of my SOAP correctly

<soapenv:Envelope xmlns:ser="http://servicos.meucliente.com.br/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-19" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>wsuser</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">wspass</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">LLxargkOakcn/LYvaUwAmw==</wsse:Nonce>
            <wsu:Created>2010-07-26T18:08:34.276Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <ser:solTarefas/>
   </soapenv:Body>
</soapenv:Envelope>

The URI of EndPoint is: HTTP not HTTPS.

All the tests I did, basically resulted in two errors. The first is reporting that the the tag <wsse:security> not been informed and the second is the transport chosen requires a HTTPS endpoint.

I need a code in C#

I try this code:
myClient.ClientCredentials.UserName.UserName = "wsuser";
myClient.ClientCredentials.UserName.Password = "wspass";
myClient.solTarefas();

but i throw Expcetion ...

My config its:
      <basicHttpBinding>
        <binding name="MyClientServiceSoapBinding" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </basicHttpBinding>

<endpoint address="http://200.211......./"
        binding="basicHttpBinding" bindingConfiguration="MyClientServiceSoapBinding"
        contract="WebService.Homologacao.MyClientHom" name="MyClientImplPort">
        <headers>
          <Username>wsuser</Username>
          <Password>wspass</Password>
        </headers>    
      </endpoint>

I try acces the WS with app. soapUI and this its fine!!!
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

ASKER CERTIFIED SOLUTION
Avatar of jefersonsv
jefersonsv
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial