开发者

Passing parameters on each wcf call

I am having this problem. I have integrated structuremap with wcf like it is described here: http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/07/29/integrating-structuremap-with-wcf.aspx

the problem is that I am having classes which have constructor parameters like userId and applicationId that I must pass in orde开发者_运维百科r structuremap can create them.

How to do this? How can i pass these parameters on each wcf call?


When you create your instance provider, get those parameters out of your message during the call to GetInstance:

public object GetInstance(InstanceContext instanceContext, Message message)
{
   YourDataContract data = message.GetBody<YourDataContract()>;
   string userID = data.userID;
   string applicationID = data.appID;

   //now go ahead and use structuremap....
}

This assumes your Message body is a defined data contract type (in my example, it's a type named 'YourDataContract').

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜