Sharing Interfaces that are implemented in WCF Service
I have wcf web service. Serice of course implements insterface with ServiceContract attribute. It also implements another interface that does not have ServiceContract attribute and is stored in exte开发者_C百科rnal dll. When I generate proxy than I do not get that second interface implemented in proxy object. Is there any way to make svcutil to generate proxy that implements it or I need to add that code manually?
Regards
If you add a reference to the assembly containing the interface definition in the project that is going to contain the proxy, the proxy generation tool will use the known interface instead of generating its own.
This doesn't make sense. If the interface is not marked as ServiceContract it is not exposed on the service and it can't be called from the proxy. If you want the proxy to implement interface as well you also have to write actual implementation of the interface in the proxy (client side!) = copy code from service. The best way is not implement interface in service but use helper class instead and share this class between client and server. You will have just single implementation and you will share it.
That is impossible. What would the implementation look like? Should it just copy-paste the implementation from the original class? If you want to expose methods as web services, you must put them in a class or interface with the ServiceContract
attribute.
Suppose the original service class looks like this:
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 proxy side? It can't simply copy your implementation from the service side.
精彩评论