C# 向WCF ServiceContract添加接口如何更改方法的URL

C# 向WCF ServiceContract添加接口如何更改方法的URL,c#,.net,wcf,web-services,interface,C#,.net,Wcf,Web Services,Interface,我试图完全理解在WCF中添加接口如何影响方法的URI。我有一个如下定义的服务合同: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceContract] public class DataService { [OperationContract] [WebGet(ResponseFormat = WebMessageFo

我试图完全理解在WCF中添加接口如何影响方法的URI。我有一个如下定义的服务合同:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public class DataService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public List<List<string>> ListTestMethod()
    {
        return new List<List<string>> 
        { 
            new List<string> {"0", "Test String 1"},
            new List<string> {"1", "Test String 2"},
            new List<string> {"2", "Test String 3"}
        };

    }

}
[ServiceContract]
public interface IDataService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    List<List<string>> ListTestMethod();
}
我得到了预期的结果:

[["0","Test String 1"],["1","Test String 2"],["2","Test String 3"]]
因此,现在我想为代码添加一个接口,如下所示:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public class DataService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public List<List<string>> ListTestMethod()
    {
        return new List<List<string>> 
        { 
            new List<string> {"0", "Test String 1"},
            new List<string> {"1", "Test String 2"},
            new List<string> {"2", "Test String 3"}
        };

    }

}
[ServiceContract]
public interface IDataService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    List<List<string>> ListTestMethod();
}
[服务合同]
公共接口IDataService
{
[经营合同]
[WebGet(ResponseFormat=WebMessageFormat.Json)]
列出ListTestMethod();
}
当然,返回DataService类并添加适当的“:IDataService”实现,同时删除接口中已经存在的装饰器。这里是我遇到麻烦的地方,因为上面的URL不再工作

我尝试将web.confg更新为此(注意名称和合同属性的更改):


这似乎让服务重新运行,但我实际上无法访问这些方法,如果我添加EnableServiceMetadata,它将无法再访问元数据(可以在原始版本中)。我已经尝试了web.config和URL的各种组合,但似乎无法让我的手臂围绕它。如何适当地连接新接口


更新

多亏了venerik,我让它工作了,但将端点更改为指向接口,但使服务保持原样:

<services>
  <service name="DataService"
           behaviorConfiguration="serviceBehavior"> 

    <endpoint address=""
              behaviorConfiguration="epBehavior" 
              binding="webHttpBinding"
              contract="IDataService.DataService" />

  </service>
</services>

我不完全相信这个答案,但我认为您的web.config应该指向以下界面:

<endpoint
    ...
    contract="IDataService"/>

您的服务主机文件应指向具体的实现:

<% @ServiceHost Language=C# Service="SomeNamespace.DataService" %>


有关

的信息,谢谢!事实上,你死定了。我的错误是我在服务声明中将名称attr更改为同时指向接口,这是错误的-它应该一直指向类本身。接口定义了signaure(即契约),而类定义了实现(服务本身)。
<% @ServiceHost Language=C# Service="SomeNamespace.DataService" %>