开发者

Sessionful wcf service in Silverlight

How can I make a sessionful wcf service for Silverlight clients? What开发者_开发百科 binding can I use?


Chapter 4 of Juval Lowy's awesome Programming WCF Services 2nd Edition is all about Instance Management. He has an entire section on Sessionful WCF services starting on page 160.

From the table on page 165 it looks like most of the bindings, including Basic, TCP, IP and WS all allow for sessionful components.

In general you add an attribute to you service contract like:

[ServiceContract(SessionMode = SessionMode.Required)]

And then you can pull the sessionId out of the context in the service like this:

string sessionId = OperationContext.Current.SessionId

On the client side, you can get the current session id like this (assuming you name your client "proxy"):

string sessionId = proxy.InnerChannel.SessionId;

Obviously there's a lot more to it, but those are the basics. I strongly suggest you take a look at Lowy's book for more information.


Normal WCF session state will unfortunately not work with Silverlight. Instead, you will have to use asp.net session state and host your app in IIS. Here is some info on how to do that:

http://pdkm.spaces.live.com/blog/cns!D1DDEC9FF002FB8C!1142.entry

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜