2016-11-19 60 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>