开发者

Automatically trim strings in inbound WCF messages

I would like to have all strings in inbound WCF messages trimmed, so that I don't have to worry about trimming them in all of my operations. I can accomplish this with an IParamet开发者_开发问答erInspector and a lot of delicate reflection logic, but it seems like there must be a better way.

I have tried using an IDataContractSurrogate, but the GetDeserializedObject does not get called for string deserialization.

Is there another way to hook into DataContractSerializer that would let me modify strings without massive reflection?


  1. You can do this by implementing IXMLSerializable. Go through this question. Of course, you need implement ReadXml operation.

  2. Whats stopping you to cast the object and updating it while inspecting the Parameter?

  3. If you think the service is used by specific .Net consumers, you can create a wcf service client, add your trimming logic to it and distribute it (so that consumers can directly make use of client instead of creating a proxy to your service). One side affect with this is you have to redistribute the client dlls whenever there is a change in the contract.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜