在 Xamarin.Forms 中将安全性 Header 添加到 SOAP Web 服务中

Add a Security Header into SOAP Webservice in Xamarin.Forms

我正在尝试从 SOAP Web 服务获取数据。我能够从测试服务中获取数据。就像这样:

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

我将服务作为 'Web Reference' 添加到 Droid-Project - 与代理一起使用 类。

现在我无法使用新的 Web 服务。问题是:我需要提供一个 Security-Header 但我真的无法让它与 Xamarin 一起工作。已经尝试在 PCL 中使用,但我也无法添加 Header。

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>
    ...

请求在 SoapUI 中有效。

通过创建第二个 wcf-service 来解决它,它消耗上面的那个。在新的中,我使用 in-code 身份验证,然后调用带有 security-header 的身份验证。唯一对我有用的解决方案。