Internal Server Error when trying to GET windows Live Contacts
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 aSystem.Net.WebException at run time.
My (C#) code is:
(whereoID 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
Thanks!!
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.
<wsp
olicyReference URI = ""MBI""></wsp
olicyReference>
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.
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 