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 =newUriBuilder();

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 welcomeSmile

Thanks!!

[3882 byte] By [littlemissconfused] at [2008-2-8]
# 1

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.

YuanYuanYu-MSFT at 2007-10-3 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Data Development...
# 2

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.
FedericoRaggi-MSFT at 2007-10-3 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Data Development...
# 3

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

littlemissconfused at 2007-10-3 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Data Development...
# 4
Great! I'm happy it worked. Let us know if you have other problems.
FedericoRaggi-MSFT at 2007-10-3 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Data Development...
# 5
Where did u download the code from?
vinay at 2008-2-11 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Data Development...

Windows Live Developer Forums

Site Classified