views:

1809

answers:

4

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 elsewhere in the project - it's a common object that they both share a reference to, as it's in the third project in my solution. When I call the webservice, it returns a "Person" object, but it's in the namespace of the webservice, and it's created from a proxy class that the webservice itself generated. As such, I can't manipulate it and return it to my program, which is expecting a "Person" object based on the shared copy of the class, not a proxy copy from the webservice namespace, and I get an error when I try to CType it to the correct class type.

How do I force the webservice to use a local copy of the class, not a proxy copy? Does my question make any sense in this context? If not, I'll clarify it.

Of note - I've resorted to passing all of the parameters ByRef, and using those returned values to populate a copy of the object I create upon return. That can't be the best way to do this!

A: 

I am not sure but when you compile a .NET web service it will create a DLL file which you can try using that for the local. But when I am building service oriented applications, I create different layers within my solution for e.g Data Access Layer, Logic Layer, Service Layer, UI Layer, Controller Layer, and for example in the Controller Layer I will do a user authentication method which is connected with the Data Access Layer and Logic Layer and then I will call that method on service layer and I can also call it on the UI layer and if I call it from within the UI layer it is called locally, when I want to use it from the service layer, I will create a web method using that method which will return a bool or username etc.

milot
A: 

I've asked this question before.

Richard Nienaber
Ah - I didn't see your question when I posted mine. Up one for you.
rwmnau
+2  A: 

If you are using svcutil.exe to generate a WCF client proxy, you can use /reference on the command-line to specify the assembly containing the common class. Svcutil should reuse that class definition instead of generating new one in the service proxy namespace.

Also, this will work only if your common class is serializable and passed by value (i.e. it's exposed as a data contract, not as a service contract).

Franci Penov
Is this different than adding a reference through the project itself? I've got my common class listed in the "References" section. I suppose I'll try this - awesome it if it works, and points to you!
rwmnau
+1  A: 

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?

smaclell