Force .NET webservice to use local object class, not proxy class

前端 未结 3 1340
猫巷女王i
猫巷女王i 2020-12-06 07:52

I have a webservice that I\'m calling from a windows forms application (both .NET, both in the same solution), and I\'d like my webservice to return a custom object from els

3条回答
  •  执念已碎
    2020-12-06 08:23

    If you are using WCF is it fairly easy to use the same data contracts and service interface between the client and the consumer. You can either compile in the generated proxy class and modify it to use the correct namespaces or use the ChannelFactory class to create a dynamic proxy for you.

    The first solution is very brittle and will cause you to modify the proxy class every time the service interface changes. The second technique works fairly well and we used in during a previous project I worked on. With either of these methods you need to make sure all your callers continue are up to date with the latest version of the interface.

    From the way you are describing the problem it sounds like you want the service and the client to share the same instance. Since WCF serializes and deserializes your types as you send them to and from the service you would have to do something a bit more clever. Is this what you meant?

提交回复
热议问题