Jagmag
Jagmag

Reputation: 10366

Namespace Issue with WCF Data Contract / Design Problem?

I am having multiple Services in my application.i have a datacontract that i need to use in more than 1 service.

Eg: class myCommonClass is being used in 2 of my services service1 and service2

To do this, at a service level, i have a MyApplication.Common library and this library contains myCommonClass. Since both my services have a reference to MyApplication.Common, they can both use it.

My client application has service references to both service1 and service2. To my client application, service1.myCommonClass is a separate namespace as compared to service2.myCommonClass and therein lies my problem

In my Reference.cs (generated via svcutil - the namespace of BOTH classes is the same i.e.

System.Runtime.Serialization.DataContractAttribute
(Name="MyCommonClass", Namespace="http://A.B.MyCommonClassNamespace")])

However, both of these are in 2 separate reference.cs files and the namespaces in the reference.cs is different due to being part of two separate service references.

Hence, to my client application they appear as two completely unrelated classes.

*Question 1 * : Is there any way that can i indicate to my client application that service1.myCommonClass and service2.myCommonClass are inherently the same class?

*Question 2 * : Is there something inherently wrong with my design here for me to run into this problem?

Upvotes: 1

Views: 1624

Answers (1)

softveda
softveda

Reputation: 11074

No, your design is fine. Instead of adding service reference from Visual Studio, generate the proxy class using svcutil on the command prompt. Create a class library project and add the generated .cs files to it. You can create a batch file and run it in pre build step as well.
Use svcutil as below to generate the proxy class in a single file from service dll (the dll that implements your two service)

svcutil.exe /t:metadata "PATH\service1.dll" "PATH\service2.dll"  
svcutil.exe /t:code *.wsdl *.xsd /o:Proxy.cs

Upvotes: 1

Related Questions