Interface sharing between WCF service and client (marked w / ServiceContract)

I am using VS2010 and .NET 4.0.

I checked here ( Common interfaces that are implemented in the WCF service ), but it differs in that I try to execute an interface that is marked with ServiceContract.

those. in the service, I have interface A (marked as ServiceContract) and extension interface B (also marked as ServiceContract). B is implemented by the WCF service.

The exact extension goes line by line:

public interface A<T> public interface B : A<SpecificType> 

("SpecificType" is marked as a DataContract.)

Obviously, B is exposed to the WCF client during proxy generation; however, I need to also open interface A (I am implementing a semi-general pub / subsystem, and the "publisher" should be able to verify / rely on interface A).

The first way I tried to solve this was to create a separate "general" assembly containing an interface, and can be used by both the service and the client; however, this doesn’t work so well, because in the publisher it needs to make sure that instance B has actually expanded with A. This implicit conversion fails, probably because the service reference does not seem completely jive with a “common” assembly.

To get around this, I manually edited the Reference.cs file and it finished the job (I added the definition of interface A and made sure interface B is related to it properly). But this creates a big problem in that every time I update the service link, this code will be destroyed.

Looking at other WCF answers on this site and others, I can’t find the exact answer (maybe I just didn’t go through all of them and their answers).

If someone can point me in the right direction, I would appreciate it.

Thanks.

+4
source share
1 answer

Provide access to the raw interfaces of service contracts for the client (assembly or link to the .cs file). Then you have two options:

1) Wrap auto-generated proxy calls in your class method calls (implement the interfaces as you like). Updating a service link will not hurt you.

2) Do not use auto-generated proxies. Create your own proxy (follow your interfaces):

 var baseAddress = "net.tcp://localhost:4503/MyService"; var channelFactory = new DuplexChannelFactory<IMyService>(new InstanceContext(new MyNotificationReceiver()), //MyNotificationReceiver - WCF callback implementation class myNetTcpBinding, new EndpointAddress(baseAddress)); var proxy = channelFactory.CreateChannel(); proxy.MyMethod(); 
+3
source

All Articles