簡體   English   中英

Web服務收到一個空的SOAP

[英]Web service receives an empty SOAP

我的android移動應用與網絡方法通信。 它們需要用戶的身份驗證,因此我像此鏈接中一樣在SOAP標頭中發送用戶名和密碼。 我檢查了它並正確生成了

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

        [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方法獲得響應

    <?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()網絡方法收到空的SOAP? 任何幫助都感激不盡。

我發現了我的錯誤。 我沒有注意標簽。 我試圖與user發送authHeaderpass

<n0:AuthHeader xmlns:n0="http://tempuri.org/">
            <n0:user>x</n0:user>
            <n0:pass>y</n0:pass>
</n0:AuthHeader>

必須使用userNamepassword SecuredTokenWebservice

 <SecuredTokenWebservice xmlns="http://tempuri.org/">
            <userName>x</userName>
            <password>y</password>
</SecuredTokenWebservice>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM