【问题标题】:WSE 3.0 creates the UsernameToken but Username and Password values are emptyWSE 3.0 创建 UsernameToken 但 Username 和 Password 值为空
【发布时间】:2012-06-18 17:07:21
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
        xmlns:tns="http://tempuri.org/" 
        xmlns:types="http://tempuri.org/encodedTypes" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <soap:Header>
                <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:mustUnderstand="1">
                    <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="unt_PQxtsT0a8iV1KN2Y">
                        <wsse:Username></wsse:Username>
                        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"></wsse:Password>
                        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">i03CXze0uiIYG8+q8MhEMYHiMcL/NOpCwvEVpQ5xo+M=</wsse:Nonce>
                        <wsu:Created>2012-04-25T22:59:23Z</wsu:Created>
                    </wsse:UsernameToken>
                    <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <wsu:Created>2012-04-25T22:59:23Z</wsu:Created>
                        <wsu:Expires>2012-04-25T22:60:23Z</wsu:Expires>
                    </wsu:Timestamp>
                </wsse:Security>
            </soap:Header>

客户端代码:

MessageServiceWse client = new MessageServiceWse();

UsernameToken usernameToken = new UsernameToken(token.Username, token.Password, PasswordOption.SendPlainText);

client.RequestSoapContext.Security.Tokens.Add(usernameToken);
client.RequestSoapContext.Security.Timestamp.TtlInSeconds = 60;

client.SomeMethod(request);

在 VS 2010 中安装和使用 WSE 3.0 的噪音太大后,我设法创建了这个漂亮的肥皂安全标头。但是,我调用这个 Web 服务(我无法控制)的地狱仍在继续,虽然看起来很糟糕好吧,我无法通过最后一个问题。

如果您注意到请求标头,您会看到一切看起来都不错,除了我传递的用户名和密码不存在!!!

有人遇到过类似的情况吗?

谢谢。

【问题讨论】:

    标签: c#-4.0 authentication ws-security wse soapheader


    【解决方案1】:

    不确定您是否仍然遇到此问题,但是您可以尝试类似的方法吗? 我不知道您为什么要尝试从令牌对象中获取用户名/密码。这是客户需要提供给服务的东西。

    UsernameToken token = new UsernameToken("myusername", "mypwd", PasswordOption.SendPlainText );
    
    client.SetClientCredential(token);
    client.SetPolicy("ClientPolicy");
    

    【讨论】:

    • 请在您的代码示例中删除额外的缩进并避免大行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 2019-02-06
    • 1970-01-01
    • 2019-06-23
    相关资源
    最近更新 更多