如何在wp8中将Header添加到Web Service调用头

时间:2013-12-19 00:18:44

标签: web-services windows-phone-8 soapheader

我是WindowsPhone 8开发的新手,并且陷入了使用Soap Header验证我的应用程序的困境。自从过去2天以来我一直在搜索网络,但无法找到可行的解决方案。

public class ValidationSoapHeader : SoapHeader
{
    private string _ValidUserID = string.Empty;
    private string _ValidPassword = string.Empty;
    private string _DeviceInfo = string.Empty;

    public string ValidUserID
    {
        get { return this._ValidUserID; }
        set { this._ValidUserID = value; }
    }    
    public string ValidPassword
    {
        get { return this._ValidPassword; }
        set { this._ValidPassword = value; }
    }
   }


 public ValidationSoapHeader Authentication;

 [WebMethod(EnableSession = true)]
    [SoapHeader("Authentication")]
    public DataSet Login_New(string username, string password)
    {
       string user = Authentication.ValidUserID; // Throws Null exception
    }

我的客户端代码是

 ValidationSoapHeader Authentication = new ValidationSoapHeader();
            Authentication.ValidPassword = txtPassword.Password.Trim();
            Authentication.ValidUserID = txtUserName.Text.Trim();


 ServiceReference1.Login_NewCompleted += ServiceReference1_Login_NewCompleted;
 ServiceReference1.Login_NewAsync(txtUserName.Text, txtPassword.Password,Authentication);

修改 我的主要问题是,当我调用Login函数时,它会在运行时在Web服务代码中抛出一个空引用,因为我将作为Login_New()的最后一个参数传递给webservice的ValidationSoapHeader的对象未分配给webservice的头功能

我的问题是如何将客户端创建的标头分配给Webservice的ValidationSoapHeader变量?

提前致谢: - )

0 个答案:

没有答案