本文介绍了将WSSE SOAP头添加到Web引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图添加一个WSSE SOAP头到我的服务调用,但大多数的例子集中在WCF。我不是使用WCF。我已经添加了一个Web引用(WSDL)。

I'm trying to add a WSSE SOAP Header to my service call, but most of the examples focusses on WCF. I'm not making using of WCF. I have added a Web Reference (WSDL).

我尝试过各种方法没有成功,像 - 覆盖GetWebRequest方法:

I have tried various methods without success, like - overriding the GetWebRequest method:

    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
        string user = "username";
        string pwd = "password";

        System.Net.WebRequest request = base.GetWebRequest(uri);

        string auth = string.Format("Basic {0}", Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(string.Format("{0}:{1}", user, pwd))));
        request.PreAuthenticate = true;
        request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
        request.Headers.Add(HttpRequestHeader.Authorization, auth);

        return request;
    }

WSSE安全标题应类似于:

The WSSE Security Header should resemble something like this:

<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <UsernameToken>
            <Username>username</Username>
            <Password>password</Password>
         </UsernameToken>
      </Security>

非常感谢!
关心,

Many thanks in advance!Kind regards,

推荐答案

请参考以下内容:

这提供了答案!

这篇关于将WSSE SOAP头添加到Web引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 23:26