Tine Kleivane
Tine Kleivane

Reputation:

WCF Proxy Types are in a Different Namespace than WCF Service Types

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

Upvotes: 1

Views: 2507

Answers (3)

Walter Almeida
Walter Almeida

Reputation: 227

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

Upvotes: 1

David M
David M

Reputation: 72890

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.

Upvotes: 1

John Saunders
John Saunders

Reputation: 161801

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

Upvotes: 1

Related Questions