Traitée Multiple contracts vs Multiple inherited interfaces

  • Tuesday, May 22, 2012 10:50 AM
     
     

    Hi guys,

    I need help about best practies to refactor/modify WCF already working.  Often, we need to add new operations or modify old operations but, these actions require the clients update. The client update is not possible in some cases (for example when the WCF is used by different clients by third parties).

    Is it possible to modify one WCF service for a new specific client without updating the clients already using the service?

    I'm trying with the following solution, but this not works correclty:

         [ServiceContract]
        public interface IBaseService
        {
            public string BaseMethod();
        }

        [ServiceContract]
        public interface IExtendedService : IBaseService
        {
            public string ExtendedMethod();
        }

        [ServiceBehavior]
        public class CalculatorService : IBaseService, IExtendedService
        {

            public string BaseMethod()
            {
                return "BaseMethod";
            }

            public string ExtendedMethod()
            {
                return "ExtendedMethod";
            }
        }

    After this I'll like to public two contrats, IBaseService for one endpoint and IExtendedService for another endpoint, but at runtime level the following error is returned:

    "This service has multiple endpoints listening witch share the same initiating action .... Please consider hosting these Endpoint at separate ListenUris."

    The error is clear, but is there a way to extends the interface and to publish the new interface in new endpoints in the same service?  Do I need to create a new  service implementing the new interface ?


    Best Regards,

    Augusto






All Replies

  • Tuesday, May 22, 2012 1:44 PM
     
     Answered Has Code

    Hi, in this instance, as you do have one contract inheriting another, the uri for both contracts must be different. for example:

    <endpoint address="" binding="basicHttpBinding" contract="IBaseService"/>
    <endpoint address="/ExtendedService" binding="basicHttpBinding" contract="IExtendedService"/>

    I used basicHttpBinding just as an example. By using the relative address on your new contract, svcutil will generate a new proxy for that endpoint. Although, you can use either proxy to call your new operation (Once it's been updated of course)
    • Edited by Dragan Radovac Tuesday, May 22, 2012 1:45 PM
    • Marked As Answer by gusy79 Tuesday, May 22, 2012 5:20 PM
    •  
  • Tuesday, May 22, 2012 5:19 PM
     
     

    Thanks, It's working correctly setting a different address.

    Best Regards,

    Augusto

  • Tuesday, May 22, 2012 5:43 PM
     
     

    Another question,

    setting a new address="/ExtendedService" the IBaseService WSDL  is changed. In the new WSDL will be add <wsdl:import ...>  for the new contract.

    This can cause some issues for dynamic soap clients. There is a way to publish the new Contract/Endpoint in the same service setting for any endpoint the WSDL URL?

    Best Regarsd,

    Augusto

  • Tuesday, May 22, 2012 6:14 PM
     
     

    Hi, your question is not clear to me. Do you mean that the dynamic soap clients are generating proxies from the wsdl on the fly and this will be causing a problem as you now have two endpoints?

  • Wednesday, May 23, 2012 7:00 AM
     
     

    Exactly,I'm talking about the dynamic soap client generating from wsdl on the fly. After the pubblication of the new endpoint for the contract ExtendedService the WSDL is changed a bit (<wsdl:import ....?wsdl=wsdl0> ).  Is there a way to customize the WSDL for both endpoints  to keep the previous URL and the previous schema for the BaseService and publish the new contract and new endpoint in other URL and other schema for the ExtendedService ?

    Thanks for your support.

    Augusto


    • Edited by gusy79 Wednesday, May 23, 2012 5:23 PM
    •