Search code examples
soapheaderwsdlxamarin.forms

Add a Security Header into SOAP Webservice in Xamarin.Forms


I'am trying to get data from a SOAP Webservice. I was able to get data from a test service. Simply like this:

var service = new CurrencyConvertor();
var f = service.ConversionRate(Currency.EUR, Currency.USD);

I added the service as 'Web Reference' into the Droid-Project - used it with proxy classes.

Now I am stuck with a new web service. The problem is: I need to provide a Security-Header and I really can't get it working with Xamarin. Already tried to use in the PCL, but there I cant add the Header too.

Webservice-Header:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header>
        <Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
          <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:Username>UserName</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
          </wsse:UsernameToken>
        </Security>
      </s:Header>
    ...

The request works in SoapUI.


Solution

  • Solved it by creating a second wcf-service, that consumes the one above. In the new one I use in-code authentification and then call the one with the security-header. Only solution that worked for me.