开发者

WCF - how to add additional data to each call

开发者 https://www.devze.com 2023-02-19 18:41 出处:网络
I want to add a complex poco that will pass itself within each wcf call. Whats the bast practice 开发者_开发知识库for this case?Typically, the best way to do something like this is passing such \"meta

I want to add a complex poco that will pass itself within each wcf call. Whats the bast practice 开发者_开发知识库for this case?


Typically, the best way to do something like this is passing such "meta-information" in a WCF header. You can easily create a message inspector to extend WCF (it's really not that scary and hard to do!) which would inject the POCO class (or what of it is necessary) into every outgoing request from the client, and retrieve it from the header and validate it on the server side.

There are a number of pretty good blog post out there showing you how to create a message inspector:

  • Richard Hallgren's WCF postings
  • Writing a WCF message inspector
  • Automatic Culture Flowing with WCF by using Custom Behaviour

Check out the two relevant interfaces to implement:

  • IClientMessageInspector on the client side, which has a BeforeSendRequest and AfterReceiveReply message to implement
  • IDispatchMessageInspector on the server side, which has a AfterReceiveRequest and BeforeSendReply method to implement


Here you go, check this out...

https://kinnrot.github.io/passing-complex-type-through-wcf/

0

精彩评论

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