Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing a same class twice using WCF

I have a 2 WCF services that are exposing the same object. Lets say the first service (SerA) exposes a class (classA) and the second service (SerB) which adds the filled classA also exposes this class (as this class is included in the parameters) Now when I retrieve the classA from SerA, it is concatenated with a namespace SerA.classA and when I add this using the second service, it requires a class like SerB.ClassA. Is there a way to specify that both classes are the same. I tried changing the namespace in reference.vb and it works but it would be real problem when the service reference is updated. Can anyone help me out in this? Thanks

like image 876
Farax Avatar asked Dec 30 '25 15:12

Farax


1 Answers

You can put your ClassA (and other data contracts) definition into a class library and reference it from both services. That way, both should be using the same DataContracts.ClassA definition.

It's always a good idea to separate your service stuff into separate projects:

  • the services (service, operation, data and possibly message contracts) into one class library ("Contracts") - possibly even into multiple libraries
  • the service implementation(s) into a class library
  • the service host(s) - if needed (not using IIS) - into a separate assembly (console app)

This way, you can reuse certain parts of your service contracts and possibly implementations, too.

MArc

like image 88
marc_s Avatar answered Jan 01 '26 21:01

marc_s



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!