首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Web服务接收空SOAP

Web服务接收空SOAP
EN

Stack Overflow用户
提问于 2016-11-19 08:52:00
回答 1查看 97关注 0票数 0

我的android移动应用程序与web方法进行通信。它们需要用户的身份验证,所以我在SOAP头中发送用户名和密码,就像在这个link中一样。我已经检查过了,它正确地生成了

代码语言:javascript
运行
复制
    <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:d="http://www.w3.org/2001/XMLSchema" 
            xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
            xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
        <v:Header>
            <n0:AuthHeader xmlns:n0="http://tempuri.org/">
                <n0:user>x</n0:user>
                <n0:pass>y</n0:pass>
            </n0:AuthHeader>
        </v:Header>
        <v:Body>
            <AuthenticationUser xmlns="http://tempuri.org/" id="o0" c:root="1" />
        </v:Body>
</v:Envelope>

但是在服务器端,web方法AuthenticationUser()接收到一个空SOAP。

代码语言:javascript
运行
复制
        [WebMethod]
    [SoapHeader("SoapHeader")]
    public string AuthenticationUser()
    {
        if (SoapHeader == null)
            return "Please provide Username and Password !" ;
        if (string.IsNullOrEmpty(SoapHeader.userName) || string.IsNullOrEmpty(SoapHeader.password))
            return "Please provide Username and Password !!" ;

        //Check is User credentials Valid
        if (!SoapHeader.IsUserCredentialsValid(SoapHeader.userName, SoapHeader.password))
            return "Invalid Username or Password !!!";

        // Create and store the AuthenticatedToken before returning it
        string token = Guid.NewGuid().ToString();
        HttpRuntime.Cache.Add(
            token,
            SoapHeader.userName,
            null,
            System.Web.Caching.Cache.NoAbsoluteExpiration,
            TimeSpan.FromMinutes(30),
            System.Web.Caching.CacheItemPriority.NotRemovable,
            null
            );
        return token;
    }

我在我的应用程序中从AuthenticationUser() web方法获得响应

代码语言:javascript
运行
复制
    <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <AuthenticationUserResponse xmlns="http://tempuri.org/">
            <AuthenticationUserResult>
                Please provide Username and Password !
            </AuthenticationUserResult>
        </AuthenticationUserResponse>
    </soap:Body>
</soap:Envelope>

我不知道为什么AuthenticationUser() web方法会接收空SOAP??任何帮助都将不胜感激。

EN

Stack Overflow用户

回答已采纳

发布于 2016-11-19 13:03:30

我发现了我的错误。我没有注意标签。我正试着把authHeaderuserpass

代码语言:javascript
运行
复制
<n0:AuthHeader xmlns:n0="http://tempuri.org/">
            <n0:user>x</n0:user>
            <n0:pass>y</n0:pass>
</n0:AuthHeader>

它必须是SecuredTokenWebserviceuserNamepassword

代码语言:javascript
运行
复制
 <SecuredTokenWebservice xmlns="http://tempuri.org/">
            <userName>x</userName>
            <password>y</password>
</SecuredTokenWebservice>
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40690958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档