.net WCF REST服务出现奇怪错误

.net WCF REST服务出现奇怪错误,.net,wcf,rest,.net,Wcf,Rest,我突然开始面临以下问题。我的休息服务不起作用了。一段时间前它还在工作,我没有对配置做任何更改。突然间,它表现得很怪异。我使用WCF测试客户端来检查问题,奇怪的是,服务方法被调用了6次,最后抛出以下错误 错误:无法从中获取元数据http://localhost:49796/Test.svc/GetInformation?memberId=1 如果这是您可以访问的Windows R通信基础服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于Exchange错误URI的M

我突然开始面临以下问题。我的休息服务不起作用了。一段时间前它还在工作,我没有对配置做任何更改。突然间,它表现得很怪异。我使用WCF测试客户端来检查问题,奇怪的是,服务方法被调用了6次,最后抛出以下错误

错误:无法从中获取元数据http://localhost:49796/Test.svc/GetInformation?memberId=1 如果这是您可以访问的Windows R通信基础服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于Exchange错误URI的MSDN文档:http://localhost:49796/Test.svc/GetInformation?memberId=1 元数据包含无法解析的引用:'http://localhost:49796/Test.svc/GetInformation?memberId=1'. 远程服务器返回意外响应:不允许使用405方法。远程服务器返回错误:405方法不允许。HTTP GET error URI:

http://localhost:49796/Test.svc/GetInformation?memberId=1

最令人惊讶的是,即使我创建了一个新服务或测试了一个旧服务,它也是一样的。我的电脑有问题吗?由于我电脑中的所有WCF REST服务的行为都相同,因此在全局某个位置似乎出现了一些文件损坏或配置更改。我在谷歌上搜索,但找不到合适的答案

我尝试删除端点,并使用测试客户端再次测试。当测试客户端自动添加basichttpbinding时,使用测试客户端工作正常

如果有人知道,请提供修复建议

我的配置如下所示:

<system.serviceModel>
<services>
  <service name="TestService.ServiceLayer.Services.TestService" behaviorConfiguration="TestBehavior">
    <endpoint address="" binding="webHttpBinding" 
              contract="TestService.ServiceLayer.Services.ITestService" behaviorConfiguration="web" />
   </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="TestBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
我的服务合同如下

 [ServiceContract]
public interface ITestService
{
    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetInformation?memberId={memberId}")]
    List<MyTestClass> GetInformation(string memberId);
}

我做了进一步的分析,发现如果我将List改为string,它就可以正常工作。我在服务合同的顶部添加了KnownType,但它不起作用。请就此行提供建议。

在您的配置中,我看不到Mex绑定。如果没有这一点,我认为无法从服务中获取元数据。Mex指的是mexHttpBinding

粗略地说,它看起来是这样的:

<services>
   <service name="MyService" behaviorConfiguration="MEX">
    <endpoint
       address="http://localhost:8000/MEX"
       binding="mexHttpBinding"
       contract="IMetadataExchange"        />
    </service>
</services>

<behaviors>
   <serviceBehaviors>
      <behavior name="MEX">
        <serviceMetadata/>
      </behavior>
    </serviceBehaviors>
</behaviors>

启用wcf跟踪并查看SvcTraceViewer.exe中的跟踪日志。查看以下链接了解如何在wcf中启用跟踪

如何使用SvcTraceViewer


这项决议令人振奋。我在DB中看到一个数据协定字段为NULL,但在C中它不是可为NULL的类型。这导致了我的REST服务的奇怪行为

我已经添加了这个并进行了测试,但没有用。我看到的主要问题是执行了6次。每次我看到正确的数据被返回,所以代码没有问题。唯一的问题是它被破坏了,我想不出来!!按照link中提供的步骤查看SvcTraceViewer.exe中的服务错误。它将提供详细的错误检查日志文件的位置我现在可以生成日志并看到一些内容,但无法理解错误仅通过查看错误消息很难判断您的服务有什么问题。我在我的回答如何使用svctraceviewer实用程序
<services>
   <service name="MyService" behaviorConfiguration="MEX">
    <endpoint
       address="http://localhost:8000/MEX"
       binding="mexHttpBinding"
       contract="IMetadataExchange"        />
    </service>
</services>

<behaviors>
   <serviceBehaviors>
      <behavior name="MEX">
        <serviceMetadata/>
      </behavior>
    </serviceBehaviors>
</behaviors>