tags:

views:

452

answers:

3

I am invoking a service through WCF and has encountered a problem with non-matching namespaces.

The object that is beeing sent though the service is in the namespace MyProject.Commons.BuisnessObjects, and I have verified this through WcfTestClient.

When I invoke a method clientside on the service (after initiated this with new MyServiceClient()), the method give me the correct objects, but with different namespaces.

The object is now of Web.MyService.Object. I have tried casting, but that didn't help.

Anyone who has seen this before?

Thanks, Tine

+1  A: 

This is the expected behavior. It's how Web Services work. They are meant to be different types.

John Saunders
OK, but is it some way of matching the namespaces? I have a MyService2 that returns MyProject.Commonc.BuisnessObjects, so there seems to be a workaround (I just can't see the difference between the two services that makes the one return a different namespace).
They are different types. You do not want them in the same namespace, unless you want every client to share the exact same DLL that the server uses. What are you trying to accomplish?
John Saunders
+1  A: 

If you have added a service reference (i.e. WCF) rather than an old fashioned web reference, then you can match these up. Add a reference to the shared library defining your object type to the client before you add the service reference, then there is an option when you add the reference to re-use types.

David M
This has the serious disadvantage that you have now created a dependency between your client and the _implementation_ of your service. Without this, there is only a dependency on the _contract_ of the service.
John Saunders
Only if you've defined the object in the same library as the implementation of your service, which I wasn't suggesting.
David M
A: 

This is because your types are not shared across service and client. Therefore the client does recreate for you your datastructures, in the Web.MyService namespace.

To avoid this you should share your data structure types between client and service by referencing your assembly containing your type BEFORE adding the service reference

You can find the detailed scenario and sample project there:

http://blog.walteralmeida.com/2010/08/wcf-tips-and-tricks-share-types-between-server-and-client.html

Walter Almeida