little miss confused


Hi all,

I am trying to use the RPS method of authentication to request information about my Windows Live contacts.

I *think* the code is okay, but I'm getting a System.Net.WebException at run time.

My (C#) code is:

(where oID is an Identity - I'm hacking about with the 'WLID Client Sample')

// Create HTTP request object.

bool bSuccess = true;

UriBuilder uriBuilder = new UriBuilder();

uriBuilder.Scheme = "HTTPS";

uriBuilder.Path = "/" + "username@hotmail.com" + "/LiveContacts/Contacts";

uriBuilder.Host = "cumulus.services.live.com";

uriBuilder.Port = 443;

string uriPath = uriBuilder.Uri.AbsoluteUri;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriPath);

request.Method = "GET";

request.Headers.Add("Authorization", "WLID1.0 t=\"t=" + oID.ExportAuthString() + "=\"");

HttpWebResponse resp = null;

try {

resp = (HttpWebResponse)request.GetResponse();

}

catch(WebException e)

{

//Console.WriteLine(e);

textBox1.Text = e.ToString();

if(e.Status == WebExceptionStatus.ProtocolError)

resp = (HttpWebResponse)e.Response;

}

The error in my Debug console is : A first chance exception of type 'System.Net.WebException' occurred in System.dll

And the exeception caught is:

System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at WindowsLiveIDClientSample.ContactsWindow..ctor(Identity oID) in C:\WLID Client Sample\src\ContactsWindow.cs:line 64

Any ideas I've spent a lot of time trawling the internet forums - but nothing seems to work (I've even tried editing the <add name="HttpGet"> approach)

Anyone had this problem Anyone see what I might be obviously doing wrong

I've never tried to develop any applications which use web services, so any really basic suggestions are welcome Smile

Thanks!!




Re: Internal Server Error when trying to GET windows Live Contacts

YuanYuan Yu - MSFT


Hi, there:

I don't see anything wrong with your code. There was indeed an internal maintence goning on a couple days ago. Maybe you just caught the bad time. Sorry about that. It should be ok now. Could you please try again If there is still a problem, please post it here again and we will troubleshoot it for you.

Thanks.







Re: Internal Server Error when trying to GET windows Live Contacts

Federico Raggi - MSFT

Dear 'little miss confused":

However, by looking at your code, I suspect the problem might be on how the Authorization header is constructed. It should be of the form:

Authorization: WLID1.0 t="<RPS Token>"

But the code you have to add the authorization header:

request.Headers.Add("Authorization", "WLID1.0 t=\"t=" + oID.ExportAuthString() + "=\"");

will produce somthing like this:

Authorization: WLID1.0 t="t=<RPS Token>="

In the text above, I marked in red the stuff I think is redundant (the additional 't=' before the token and the '=' at the end) but I might be wrong because I'm not familiar with the token that the WL ID client returns. I'll investigate a little more about the WLID client to see if I'm right or not.

In the meantime, try this code to generate the authorization header and let me know if it works:

request.Headers.Add("Authorization", "WLID1.0 t=\"" + oID.ExportAuthString() + "\"" );

Also, the problem might be with how you generate the token with WL ID client. You need to get a ticket using the MBI policy. How are you getting the ticket Are you using Ws-Trust If you are, check your PolicyReference on the XML for the call to Ws-Trust is defined as ˇ°MBIˇ± as shown below.

<wspStick out tongueolicyReference URI = ""MBI""></wspStick out tongueolicyReference>

Let me know if these suggestions work!

P.S: A 500: Internal Server error typically indicates a problem with our server, not with your code so I'll check why we are returning that error.






Re: Internal Server Error when trying to GET windows Live Contacts

little miss confused

Wow, thanks so much Federico!

That really helped, I'm now using the correct TicketAcquirer (which I should really have tried first...)

TicketAcquirer t = new TicketAcquirer();

string str = t.GetTicket();

...

request.Headers.Add("Authorization", "WLID1.0 t=\"" + str + "\"");

Works a treat and I have successfully returned all my msn contacts!

Thanks to both of you for your quick replies! I'd have never got anywhere without them





Re: Internal Server Error when trying to GET windows Live Contacts

Federico Raggi - MSFT

Great! I'm happy it worked. Let us know if you have other problems.




Re: Internal Server Error when trying to GET windows Live Contacts

Fernando Simonazzi

Using the TicketAcquirer requires managing username/password.

You can get the appropriate token from the Identity object by doing something like

string ticket = identity.GetTicket("http://live.com", "MBI", false);

request.Headers.Add("Authorization", "WLID1.0 t=\"" + ticket + "=\"");

Fernando





Re: Internal Server Error when trying to GET windows Live Contacts

Qasem Elmogy

Dear Mr.Fernando,

Could you please Explain how to GetTicket by this way

string ticket = identity.GetTicket("http://live.com", "MBI", false);

which i didn't know what do you mean by false in this line of code

and how to implement this method

thanks alot

Qassem






Re: Internal Server Error when trying to GET windows Live Contacts

Fernando Simonazzi

Hi,

You can get information about this from the method from the API reference at http://msdn2.microsoft.com/en-us/library/bb404831.aspx, including a code sample.

Not sure what you mean by implementing this method.

Fernando