skip to Main Content

I have some client and server that communicates via WCF services. I need to create "proxy" between them to filtrate responses. I’ve managed to create small .NET 8.0 application that accepts TCP sockets from clients and forwards all data to server. But responses that comes from the server makes no sense at all. Here is sample responseWhat im getting from server as raw bytes converted to UTF-8

Any ideas how i can convert this to actual object? I know how class should look like. It just one bool and two ArrayList/object[] fields.

I create small console utility that does binary serialization with DataContractSerializer and XmlDictionaryWriter.CreateBinaryWriter. But result is close but not the same.Result of .NET Framework 4.8.1 serialization

Also i’ve tried to go in this direction http://blog.functionalfun.net/2009/11/fiddler-plug-in-for-inspecting-wcf.html. But i had xml incorrect format exceptions

2

Answers


  1. Chosen as BEST ANSWER

    i had to go in another direction. I found .dll with contracts and created small console application where i add same endpoints as in server web.config and also i implemented wrapper for every service contract from that .dll. It works now, but i had to do much more useless work for setting up all stuff.

    btw data were in Latin1 encoding, but anyway it not the format when i tried to serialize objects with BinaryFormatter/BinaryWritter. My guess is that data came so messy because of how Castle.Core dynamic class building stuff works with ServiceModel WCF stuff.


  2. There is some information about this in WCF: Serialization and Deserialization

    WCF also includes a companion serializer, the NetDataContractSerializer. The NetDataContractSerializer:

    • Is not secure. For more information, see the BinaryFormatter security guide.
    • Is similar to the BinaryFormatter and SoapFormatter serializers because it also emits .NET Framework type names as part of the serialized data.
    • Is used when the same types are shared on the serializing and the deserializing ends.

    BinaryFormatter has been deprecated. For good reasons.

    My understanding is that BinaryFormatter essentially dumps the in memory representation of objects, with only minor fixes to adjust addresses, types etc. This approach is fairly fragile, and notoriously insecure. But there are probably lots of details I’m ignorant about. As far as I know the exact format is not documented.

    You either need to make your proxy ignorant of the package contents, or switch to a serialization protocol that is supported on modern .net. You could perhaps use EnableUnsafeBinaryFormatterSerialization to enable support, but it is not something I would recommend. The sooner you migrate to a supported solution the less problems you will have long term.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search