2016-11-19 74 views
0

我的android手機應用程序與web方法進行通信。他們需要用戶的身份驗證,所以我在SOAP頭中發送用戶名和密碼,如link。我檢查了它,它產生正確Web服務收到一個空的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> 

但在服務器端,AuthenticationUser()收到一個空SOAP Web方法。

 [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() Web方法接收空SOAP?任何幫助都感激不盡。

+0

打印響應,看看它是那裏。 – HaroldSer

+0

我做到了。看到上面的XML,它返回'請提供用戶名和密碼! '當SOAP頭爲空時返回'if(SoapHeader == null) return「請提供用戶名和密碼!」 ;' –

回答

0

我發現我的錯誤。我沒有注意標籤。我試圖發送authHeaderuserpass

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

它必須是SecuredTokenWebserviceuserNamepassword

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