views:

29

answers:

3

Hello,

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 external 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

A: 

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.

klausbyskov
The problem is that implemented interfaces that are not marked with any attribute are skipped by proxy generation tool
Marek
A: 

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.

Ronald Wildenberg
The problem is that implemented interfaces that are not marked with any attribute are skipped by proxy generation tool
Marek
a bug in stackoverflow - added comment to previous answer - during that time new answer appeared and comment goes to wrong answer
Marek
Comment for this one: This is Service: class EchoImplementation : IEchoContract, Interface1 { public EchoMessage Echo(EchoMessage Message) { EchoMessage _returningMessage = new EchoMessage(); _returningMessage.ReturnMessage = Message.OutMessage; return _returningMessage; } #region Interface1 Members public void dummy() { } #endregion }
Marek
This is contract [ServiceContract] public interface IEchoContract { [OperationContract] EchoMessage Echo(EchoMessage Message); }This is additional interface: public interface Interface1 { void dummy(); }
Marek
..and this is Proxy for that is generated (in vb) (implements only IEchoContract): <System.Diagnostics.DebuggerStepThroughAttribute(), _ System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")> _ Partial Public Class EchoContractClient Inherits System.ServiceModel.ClientBase(Of Proxy.IEchoContract) Implements Proxy.IEchoContract Public Sub New() MyBase.New End Sub
Marek
So in proxy there is no Interface1 implemented - why?
Marek
Because you don't expose Interface1 as a service. It's all in my answer.
Ronald Wildenberg
A: 

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.

Ladislav Mrnka