Injection of an unbound contract in a WSDL generated by the WCF MEX provider

I am implementing a WCF service (Contract A) that ultimately makes calls to a standalone service (Contract B) hosted by a client. At design time, when a client requests my WSDL service to build their proxy, I would like to include WSDL for contract B so that the client can build their service around that. Unfortunately I can't figure out how to inject contract B into the WSDL emitted by the service. Since the contract is an interface and has no [DataContract] attribute, I cannot add it as a known type. Is there any other way to inject the contract into the emitted WSDL?

Here's an example:

[ServiceContract]
public interface IServerService
{
  [OperationContract]
  void GiveTheServerMyServiceUri(string uri);

  [OperationContract]
  void TellAllClientsSomething(string message);
}

// THIS IS THE INTERFACE I WANT TO INCLUDE IN THE WSDL
[ServiceContract]
public interface IClientService
{
  [OperationContract]
  void ReceiveMessageFromServer(string message);
}

public class ServerService : IServerService
{
  private List<string> knownClients;

  public void GiveTheServerMyServiceUri(string uri)
  { 
    knownClients.Add(uri);
  }

  public void TellAllClientsSomething(string message)
  {
    foreach (string clientUri in knownClients)
    {
      // 1. Create instance of ClientServiceProxy using client uri
      // 2. Call proxy.ReceiveMessageFromServer(message)
    }
  }
}

      

At first it seems like this is a tutorial example of a duplex contract. However, for this particular application, for various reasons, I need a little more separation between client and server, so I was hoping to just give the client an interface to implement (via WSDL), let it host its own service, then just tell me the URL of the service.

0


a source to share


1 answer


I don't see it makes sense. If your service is not fulfilling a service contract for another service, then do not.

On the other hand, your service may implement a different service contract and become a client of another service. He can then delegate calls to another service contract for that other service.


I just tried this to be sure. I created a new WCF Service library project. This created Service1 implementing IService1 with two operations. I changed the [ServiceContract] attribute to use a specific namespace ( http: // localhost / service1 ).



Then I added a new service that Service2 provided me, implementing IService2, with one operation (DoWork). I updated [ServiceContract] to use http: // localhost / service2 / .

Then I updated Service1 to implement IService2 as well as IService1 and delegate IService2.DoWork to Service2. I also had to add a new endpoint that implements IService2 and I had to provide a relative address so they don't clash (since they were in the same project). Here's the result:

using System;

namespace WcfServiceLibrary1
{
    public class Service1 : IService1, IService2
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        public void DoWork()
        {
            Service2Reference.IService2 svc = null;
            try
            {
                svc = new Service2Reference.Service2Client();
                svc.DoWork();
            }
            finally
            {
                if (svc != null)
                {
                    ((IDisposable)svc).Dispose();
                }
            }
        }
    }
}

      

+1


a source







All Articles