locked
Configuring a web service with multiple interfaces RRS feed

  • Question

  • User201331998 posted

    I am new to creating web services.  I am refactoring  web service from VB to C#.  It is one web service but has 2 interfaces.   The interfaces have a method that has the same name but a different parameter list.  I believe that is the problem.  I would like to be able to keep this design if possible.

    This is the service contracts for each interface:

    Interface 1:

    namespace PayService
    {
        [ServiceContract (Namespace defined here)]
        public interface IPayService1
        {
            [OperationContract(IsOneWay = true)]
            void Authorize(...12 parameters defined ...)
    
            More methods defined here
        }
    }
    

    Interface 2:

    namespace PayService
    {
        [ServiceContract (Namespace defined here)]
        public interface IPayService2
        {
            [OperationContract(IsOneWay = true)]
            void Authorize(...13 parameters defined ...)
    
            More methods defined here but they are not the problem...
        }
    }
    

    The Service file implements the 2 interfaces...

    public class PayService : IPayService1, IPayService2
    {
       Authorize( ...12 parameters...)
       Authorize(...13 parameters...)
    
       Rest of methods...
    }

    The PayService web.config file:

     <bindings>
        <basicHttpBinding>
          <binding name="myBindingConfiguration1" closeTimeout="00:01:00" />
        </basicHttpBinding>
      </bindings>
    <services>
          <service behaviorConfiguration="PayServiceBehavior" name="PayService.PayService">
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1"
              name="PayService1" contract="PayService.IPayService1" />
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1"
              name="PayService2" contract="PayService.IPayService2" />
          </service>
    </services>
     <serviceBehaviors>
            <behavior name="PayServiceBehavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true" />
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
    

    This is the client web.config file

    <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_IPayService" />
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IPayService" contract="PayService.IPayService1"
            name="PayService1" />
          <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IPayService" contract="PayService.IPayService2"
            name="PayService2" />
        </client>
      </system.serviceModel>
    

    If I only have 1 endpoint in each of the web.config files, the Service Reference can update and the test client application can call the Authorize method.  But when I add the 2nd endpoint, I get the error:

    The client and service bindings may be mismatched...content type 'application/soap+xml' was not expected type text/xml.

    This error implies that the client is trying with one type of SOAP and the service with another type of SOAP.  But I am using the same binding for both endpoints. And as I wrote above, when I only use one of the endpoints, the service works fine.

    Is the problem that the 2 interfaces have methods with different signatures but the same name?

    I would greatly appreciate any help!

    Thanks!

    Monday, February 17, 2014 9:17 AM

Answers

  • User201331998 posted

    I have posted this problem on 2 other forums. Although you should be able to have 2 interfaces with the same method name but different signatures and use 2 endpoints to access each of the interfaces, I do not believe it is possible UNLESS you do one of the following:

    1. The namespace for each interface is unique.
    2. The name attribute for the overloaded method is unique.

    I choose the first option because I am updating legacy code and adding the name attribute to the method essentially changes the name of the method.  So all of the client applications that use this method in the service will need to be changed.  I wanted to minimize the changes to these applications so I went with changing the namespace.

    I thought that this namespace attribute is used to point to a location where the service resides.  According to the Microsoft documentation and my limited local testing, this is not the case.  This is an excerpt of the documentation:

    Identify your XML Web service with a namespace that you control. For example, you can use the Internet domain name of your company as part of the namespace. Many XML Web service namespaces look similar to URLs, however, namespaces do not have to point to actual resources on the Web. (XML Web service namespaces are URIs.) (Uniform Resource Identifier). By using XML namespaces you can uniquely identify elements or attributes in a xml document. The service description for a xml web service is in xml, specifically in WSDL.

    I hope this can help someone else with this problem...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 18, 2014 8:44 AM

All replies

  • User201331998 posted

    I have posted this problem on 2 other forums. Although you should be able to have 2 interfaces with the same method name but different signatures and use 2 endpoints to access each of the interfaces, I do not believe it is possible UNLESS you do one of the following:

    1. The namespace for each interface is unique.
    2. The name attribute for the overloaded method is unique.

    I choose the first option because I am updating legacy code and adding the name attribute to the method essentially changes the name of the method.  So all of the client applications that use this method in the service will need to be changed.  I wanted to minimize the changes to these applications so I went with changing the namespace.

    I thought that this namespace attribute is used to point to a location where the service resides.  According to the Microsoft documentation and my limited local testing, this is not the case.  This is an excerpt of the documentation:

    Identify your XML Web service with a namespace that you control. For example, you can use the Internet domain name of your company as part of the namespace. Many XML Web service namespaces look similar to URLs, however, namespaces do not have to point to actual resources on the Web. (XML Web service namespaces are URIs.) (Uniform Resource Identifier). By using XML namespaces you can uniquely identify elements or attributes in a xml document. The service description for a xml web service is in xml, specifically in WSDL.

    I hope this can help someone else with this problem...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 18, 2014 8:44 AM
  • User2075212911 posted

    Hi gloria10,

    Glad to hear you solved this issue by self and thanks for sharing your solution.

    There are similar issues may be helps.

    http://stackoverflow.com/questions/16501681/host-multiple-contracts-in-one-wcf-service

    http://stackoverflow.com/questions/720376/multiple-interfaces-from-a-single-wcf-service

    Wednesday, February 19, 2014 6:34 AM