Home » SQL ServerRSS

Silverlight 4 and IClientMessageInspector don't give access to the [Set-Cookie] http header

Hi,

I added a new MessageInspector to my Wcf client runtime (in sl4) to intercept all the replies from the server, and then gain access to http headers.

 

    public void AfterReceiveReply(ref Message reply, object correlationState)
{
var httpResponse = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name];
var httpHeaders = httpResponse.Headers.AllKeys;
}


It works fine but i don't see any Set-Cookie header in the reply whereas in Fiddler it appears to be here ???

In the httpHeaders variable above there are for example headers like : Cache-Control, Content-Length, Content-Type, X-Powered-By etc..

Do you know why the Set-Cookie http header is not return ?

Thanks in advance

++

 

2 Answers Found

 

Answer 1

There are some headers  in Silverlight which are not exposed in the WebHeaderCollection, so I'm assuming Set-Cookie is one of them. To be able to see the cookies sent by the server, I think you'll need two things:

1. Use the client http  stack (and not the browser stack, which is the default). If you use the browser networking stack, it will take care of the cookies for you, and you won't have access  to them. To set the client  stack, see http://msdn.microsoft.com/en-us/library/dd920295(VS.95).aspx.

2. Use the CookieContainer (which can be set on the client proxy generated by slsvcutil / Add Service Reference) to retrieve the cookies set by the service. The CookieContainer is how you can deal with cookies when using the client HTTP stack.

 

Answer 2

Hi Carlos,

I use now the CookieContainer and it does the work. Thanks.

++

Stimentic

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter