Question

Hi i have this problem with some authentication and creation of database item. In the documentation it says that authentication should be called before the creation. So here is the code i have done and i wonder if i have the events in wrong order.

private void ApplicationBarIconButton_Click_5(object sender, EventArgs e)
    {
        Gateway.AuthenticateAsync("username", "password1", "username2", "password2");
        Gateway.AuthenticateCompleted += new EventHandler<ServiceReference.AuthenticateCompletedEventArgs>(AuthenticateTime);    
    }

    private DateTime _nestedDateStart;
    private DateTime _nestedDateEnd;
    private DateTime _nestedDateStartBreak1;
    private DateTime _nestedDateEndBreak1;
    private DateTime _nestedDateStartBreak2;
    private DateTime _nestedDateEndBreak2;

    ServiceReference.TimereportDto Timereport = new ServiceReference.TimereportDto();

    void AuthenticateTime(object sender, ServiceReference.AuthenticateCompletedEventArgs e)
    {

        Gateway.AuthenticateAsync("username1", "password1", "username2", "password2");     

        Timereport.Started = _nestedDateStart;
        Timereport.Ended = _nestedDateEnd;

        Timereport.Break1Start = _nestedDateStartBreak1;
        Timereport.Break1End = _nestedDateEndBreak1;

        Timereport.Break2Start = _nestedDateStartBreak2;
        Timereport.Break2End = _nestedDateEndBreak2;

        Timereport.Comment = Notes.Text;
        Timereport.EmployeeSignature = "apptest";

        Gateway.CreateTimereportAsync(Timereport,"ABD");
        Gateway.CreateTimereportCompleted += new EventHandler<ServiceReference.CreateTimereportCompletedEventArgs>(CreateTimereportCompleted);

    }

    void CreateTimereportCompleted(object sender, ServiceReference.CreateTimereportCompletedEventArgs e)
    {

    }

When i set a Breakpoint on "CreateTimereportCompleted" i get error as shown below in the image:

enter image description here

As you can see it returns message "Access denied,please login first". So becaus the usernames and passwords are correct i figure that i must have the code in wrong order or something.

UPDATE

Gateway is a servicereference that looks like this:

ServiceReference.GatewaySoapClient Gateway = new ServiceReference.GatewaySoapClient();

And if the Authentication cookie is supposed to be passed to the next service call i dont know. Nothing is saying that in the documentation.

They have in the documentation below the Authentication a CookieContainer but isnt that only when you make it for a webbrowser?

Anyone who can help me?

Was it helpful?

Solution

Method 1:- (Without forcefully passing cookies through code)

In your ASMX web config add aspNetCompatibilityEnabled="true" and set AllowCookies=false

In your ServiceReferences.ClientConfig add AllowCookieContainer=true

Method 2:- (Passing cookies around via code)

In your ASMX web config set AllowCookies=true In your ServiceReferences.ClientConfig add AllowCookieContainer=true and you can set

client.CookieContainer=yourCookieContainerVariable

and pass along this 'yourCookieContainerVariable' to next service call.

This method is particularly useful when you have a separate url for your authenticationa nd other business functions

As depicted in : http://www.kotancode.com/2010/08/06/aspnet-authentication-wp7/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top