none
Web service with multiple interfaces and overloaded methods RRS feed

  • Question

  • I need to be able to configure an endpoint for each interface that I have in a web service that I created.
    Using a test web form application, I can successfully use either interface. But when I try to add a second endpoint with the second interface, I get the error below:

          

    Here are the web.config file for the web service:

      <basicHttpBinding>
              <binding name="myBindingConfiguration1" closeTimeout="00:01:00" />
            </basicHttpBinding>
     </bindings>
     
           <services>
              <service behaviorConfiguration="PaymentServiceBehavior" name="PaymentService.PaymentService">
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1"
                  name="PaymentInsecureService" contract="PaymentService.IPaymentService" />
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1"
                  name="PaymentSecureService" contract="PaymentService.IPaymentSecureService" />
              </service>
            </services>

      



    This is the web.config file from the test application:

      <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_IPaymentService" />
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IPaymentService" contract="PaymentService.IPaymentService"
            name="PaymentInsecureService" />
          <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IPaymentService" contract="PaymentService.IPaymentSecureService"
            name="PaymentSecureService" />
        </client>



    This is the code for the web service interfaces:

        namespace PaymentService
        {
            [ServiceContract (Namespace = "name of namespace here")]
            public interface IPaymentSecureService
            {
                //Initiate a credit card authorization.
                [OperationContract(IsOneWay = true)]
                void Authorize(...12 parameters here...);
                more methods here....
            }
        }
        namespace PaymentService
        {
            [ServiceContract (Namespace = "name of namespace here")]
            public interface IPaymentService
            {
                //Initiate a credit card authorization.
                [OperationContract(IsOneWay = true)]
                void Authorize(...13 parameters here....);
                more methods here...
            }
        }

    Is it possible to have an endpoint for each interface when one of the interface methods is overloaded?

    Is there something wrong with my config files?

    I have checked the bindings and configuration but cannot find why the client and service report a mismatch in the bindings.

    Thanks.

              

    • Edited by GSan1 Monday, February 17, 2014 4:10 PM formatting
    Monday, February 17, 2014 3:39 PM

Answers

  • I *think* for the namespace change, you'd just have to right click the reference and select "Update Service Reference", as my recollection is that namespace is all isolated to the auto-gen'ed code, and your clients' proxies would remain unchanged on the surface.
    Monday, February 17, 2014 9:06 PM

All replies

  • Overloads aren't going to work in WCF. You can overload them at the interface level, but at the contract level, they should have different names. OperationContractAttribute lets you specify a name that differs from the coded name.
    Monday, February 17, 2014 4:44 PM
  • They are overloaded at the interface level.

    I have 2 interfaces, IPaymentService and IPaymentSecureService.  They implement the Authorize Method but the parameter list is different for each Authorize method.  One has 13 parameters, the other 12 parameters.

    Is this not allowed?

    Monday, February 17, 2014 4:50 PM
  • Sorry, I read your post too quickly. AFAIK, what you are trying to do is legal, since you've got different endpoints for the interfaces, meaning you shouldn't have an operation collision. I had the same error you had (mismatched bindings) last week but can't recall how I resolved it. I'll play around a bit with it this afternoon to see if I can jog my memory.
    Monday, February 17, 2014 6:32 PM
  • Thank you for helping.

    It seems like it has to do with my settings in one or both of my configurations files.  I am testing this web service locally so the web service and test client are both on my machine and using IIS to host the web service. 

    I don't know that maybe doing everything on a local machine may be why it cannot resolve the issue.

    Monday, February 17, 2014 7:17 PM
  • Well, consider myself surprised - even though the two methods are defined on different interfaces with different endpoints, WCF still doesn't like the overload; I would have figured the implementing service to be irrelevant, but not so.

    You can either give the two interfaces separate namespaces or give the operations unique names. I've tried both and am able to access the service reference.

    Monday, February 17, 2014 7:28 PM
  • This is not a new web service, but I am refactoring a current service.  To minimize the changes that I would have to do to the client applications that use this service, would it be better to change the namespace?  I have tried adding the attribute names to the operations and it gives the operations different names.  So I would have to update all of the client apps that use these operations with the new name.

    What changes would I have to do to the client applications if I change the namespace? 

    It is an URL.  Doesn't that tell the client applications where to access the web service?


    • Edited by GSan1 Monday, February 17, 2014 7:44 PM grammar
    Monday, February 17, 2014 7:43 PM
  • I *think* for the namespace change, you'd just have to right click the reference and select "Update Service Reference", as my recollection is that namespace is all isolated to the auto-gen'ed code, and your clients' proxies would remain unchanged on the surface.
    Monday, February 17, 2014 9:06 PM