How to add Header to Webservice call header in wp8

187 views Asked by At

I'm new to WindowsPhone 8 development and got stuck in Authenticating my app using Soap Header. I've been searching web since last 2 days but couldn't able to find working solution.

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
    }

My Client code is

 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);

Edit: MY main problem is when i call the Login function it throws a null reference at run-time in web-service code, Thats because object of ValidationSoapHeader that i passed to webservice as a last argument of Login_New() is not assigned to header of webservice function

And my Question is How i can assign the header created at client side to the ValidationSoapHeader variable at Webservice?

Thanks in Advance :-)

0

There are 0 answers