Search code examples
c#restwcfsoapui

Multiple contracts in one WCF service_But error for calling the second contract


I have multiple contracts in one WCF:

namespace SysLap.Services.Web.DataExtractor
{
    [ServiceContract]
    public interface IServiceDataExtractor
    {      
        [OperationContract]
        [WebGet]
        List<User> GetAllUsers(/*CommonParams commonParams*/);
    }

    [ServiceContract]
    public interface IScopesExtract
    {
        [OperationContract]
        [WebGet]
        List<SyScope> GetAllScopes();
    }
}

and the Web.config is well configured:

 <endpoint address="rest" behaviorConfiguration="restBehavior"
      binding="webHttpBinding" contract="SysLap.Services.Web.DataExtractor.IServiceDataExtractor" />
    <endpoint address="rest" behaviorConfiguration="restBehavior"
      binding="webHttpBinding"  contract="SysLap.Services.Web.DataExtractor.IScopesExtract" />
  </service>

For the service GetAllUsers, it is worked very good. But for the service GetAllScopes, when i test it with SOAP UI, i am getting this error:

<p class="heading1">Request Error</p>
    <p>The server encountered an error processing the request. The exception message is 'Multiple filters matched.'.
        See server logs for more details. The exception stack trace is: </p>
    <p> at System.ServiceModel.Dispatcher.EndpointDispatcherTable.LookupInCache(Message message, Boolean&amp;
        addressMatched)
        at System.ServiceModel.Dispatcher.EndpointDispatcherTable.Lookup(Message message, Boolean&amp;
        addressMatched)
        at System.ServiceModel.Dispatcher.ChannelHandler.GetDatagramChannel(Message message, EndpointDispatcher&amp;
        endpoint, Boolean&amp; addressMatched)
        at System.ServiceModel.Dispatcher.ChannelHandler.EnsureChannelAndEndpoint(RequestContext request)
        at System.ServiceModel.Dispatcher.ChannelHandler.TryRetrievingInstanceContextCore(RequestContext request)
    </p>

How can I fix it?

Thanks


Solution

  • When we use the WCF project template to create WCF service, normally there is only one service host in Service.svc(Markup).

    <%@ ServiceHost Language="C#" Debug="true" Service="WcfService3.Service1" CodeBehind="Service1.svc.cs" %>
    

    It means that we could have multiple service contracts, but we merely can have one service(service implementation class).
    Under this circumstance, hosting multiple service contracts in one project is valid.

    public class Service1 : IService1,IService2
    

    Back to your problem, the error mainly indicates that our services have the same relative address, this does not comply with the WCF addressing specification.
    As Selim Yıldız said, we need two separate endpoint address.

        <services>
          <service name="WcfService3.Service1">
            <endpoint address="a" binding="webHttpBinding" contract="WcfService3.IService1" behaviorConfiguration="rest"></endpoint>
            <endpoint address="b" binding="webHttpBinding" contract="WcfService3.IService2" behaviorConfiguration="rest"></endpoint>
          </service>
    </services>
    

    The service Url will be,

    http://xxxx:xx/service1.svc/a/GetAllUsers
    http://xxxx:xx/service1.svc/b/GetAllScopes

    Feel free to let me know If there is anything I can help with.