Sharing Interfaces Implemented in the WCF Service

I have a wcf web service. Of course, Serice implements an insterface with the ServiceContract attribute. It also implements another interface that does not have a ServiceContract attribute and is stored in an external dll. When I create a proxy server, I do not get this second interface implemented in the proxy object. Is there a way to make svcutil to create a proxy server that implements it, or do I need to add this code manually?

Hello

0
source share
3 answers

If you add a link to the assembly containing the definition of the interface in the project that will contain the proxy server, the proxy server generation tool will use the well-known interface instead of generating its own.

0
source

It's impossible. What will the implementation look like? Should it just copy the implementation insert from the source class? If you want to expand methods as web services, you must put them in a class or interface with the ServiceContract attribute.

Suppose the source class of the service is as follows:

 public class MyService : IServiceContract, IOtherInterface { ... public ObjectFromServiceAssembly MethodFromOtherInterface() { Console.WriteLine("Create instance of some object."); return new ObjectFromServiceAssembly(); } } 

How would MethodFromOtherInterface look on the generated side of the proxy? It cannot just copy your implementation from the service side.

0
source

It does not make sense. If the interface is not marked as ServiceContract, it is not displayed in the service and cannot be called from the proxy. If you want the proxy to also implement the interface, you also need to write the actual implementation of the interface in the proxy (client side!) = Copy code from the service. The best way is not to implement the interface in the service, but instead use a helper class and share this class between the client and server. You will have only one implementation, and you will share it.

0
source

All Articles