【发布时间】:2014-01-13 14:41:41
【问题描述】:
我突然开始面临以下问题。我的 REST 服务不再有效。它在一段时间前工作,我没有对配置进行任何更改。突然之间,它的行为很奇怪。我使用 WCF 测试客户端检查问题,奇怪的是,服务方法被调用了 6 次,最后抛出以下错误。
错误:无法从http://localhost:49796/Test.svc/GetInformation?memberId=1 获取元数据如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange 错误 URI:http://localhost:49796/Test.svc/GetInformation?memberId=1 元数据包含无法解析的引用的 MSDN 文档:“http://localhost:49796/Test.svc/GetInformation?memberId=1”。远程服务器返回意外响应:(405) 方法不允许。远程服务器返回错误:(405) Method Not Allowed.HTTP GET Error URI:
http://localhost:49796/Test.svc/GetInformation?memberId=1
There was an error downloading 'http://localhost:49796/Test.svc/GetInformation?memberId=1'. The underlying connection was closed: An unexpected error occurred on a receive. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. An existing connection was forcibly closed by the remote host
最令人惊讶的是,即使我创建一个新服务或测试一个旧服务,它也是一样的。我的电脑在全球范围内出现问题了吗?由于我电脑中的所有 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 更改为字符串,它可以正常工作。我在服务合同之上还添加了 KnownType,但它不起作用。请就这一行提出建议。
【问题讨论】: