与WCF REST服务奇怪的错误 [英] Strange error with WCF REST Services

查看:162
本文介绍了与WCF REST服务奇怪的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我突然开始面临如下问题。我的REST服务没有更多的作品。这是工作一段时间以前,我没有做任何更改配置。由于突如其来的,它是行为怪异。我用WCF测试客户端检查的问题,奇怪的是,该服务方法被调用6次,最后抛出下面的错误。

错误:无法从 HTTP获取元数据://本地主机:49796 / Test.svc / GetInformation会员id = 1 如果这是Windows(R)通信基础服务您有权访问,请检查您是否已经启用了元数据发布在指定的地址。为了帮助实现元数据发布,请参阅MSDN文档的的http://去.microsoft.com / fwlink / LINKID = 65455.WS元数据 Exchange错误网址:<?code>的http://本地主机:49796 / Test.svc / GetInformation会员id = 1 元数据包含了一个参考无法得到解决:的http://本地主机:49796 / Test.svc / GetInformation会员id = 1 ?。远程服务器返回了意外的响应:(405)不允许的方法。远程服务器返回错误:(405)方法不Allowed.HTTP得到错误的URI:

  

的http://本地主机:49796 / Test.svc / GetInformation会员id = 1

 有一个错误下载'的http://本地主机:49796 / Test.svc / GetInformation会员id = 1'。基础连接已关闭:接收时发生意外错误。无法读取传输连接的数据:一个现有的连接被强行关闭远程主机。一个现有的连接被强行关闭远程主机
 

最令人惊讶的是,这是一样的,即使我创建了一个新的服务或者测试一个旧的服务。难道出事了在我的电脑在全球范围?这似乎是一些文件损坏或改变配置全球范围内的某个地方,因为所有的WCF REST服务在我的电脑的行为是一样的。我用Google搜索,但没有找到任何合适的回答。

我试图消除终点,并再次测试使用测试客户端。由于测试客户端增加了自动basicHttpBinding的,它工作正常使用测试客户端。

请告知此修复程序,如果有人知道。

我的配置看起来如下:

 &LT; system.serviceModel&GT;
&LT;服务&GT;
  &LT;服务名称=TestService.ServiceLayer.Services.TestServicebehaviorConfiguration =TestBehavior&GT;
    &LT;端点地址=绑定=的WebHttpBinding
              合同=TestService.ServiceLayer.Services.ITestServicebehaviorConfiguration =网/&GT;
   &LT; /服务&GT;
&LT; /服务&GT;
&LT;行为&GT;
  &LT; endpointBehaviors&GT;
    &LT;行为NAME =网络&GT;
      &LT; webHttp /&GT;
    &LT; /行为&GT;
  &LT; / endpointBehaviors&GT;
  &LT; serviceBehaviors&GT;
    &LT;行为NAME =TestBehavior&GT;
      &LT; serviceMetadata httpGetEnabled =真/&GT;
      &LT; serviceDebug includeExceptionDetailInFaults =真/&GT;
    &LT; /行为&GT;
    &LT;行为NAME =&GT;
      &LT; serviceMetadata httpGetEnabled =真httpsGetEnabled =真/&GT;
      &LT; serviceDebug includeExceptionDetailInFaults =真/&GT;
    &LT; /行为&GT;
  &LT; / serviceBehaviors&GT;
&LT; /行为&GT;
 

我的服务合同如下

  [的ServiceContract]
公共接口ITestService
{
    [OperationContract的]
    [WebInvoke(方法=GET,ResponseFormat = WebMessageFormat.Json,UriTemplate =GetInformation?会员id = {}会员id)]
    名单&LT; MyTestClass&GT; GetInformation(字符串会员id);
}
 

我进一步分析后发现,如果我改变列表以字符串它工作正常。我说KnownType以及对服务合同的顶部,但它不工作。请告知此行。

解决方案

分辨率是令人兴奋的。我看到的数据契约字段之一为NULL在DB但它不是空类型在C#。这是导致奇怪的行为我REST服务。

I have suddenly started facing the below issue. My REST Service no more works. It was working sometime ago and I didn't make any changes to config. As of sudden, it is behaving weird. I used WCF Test client to check the issue and strangely, the service method gets called 6 times and finally throws the below error.

Error: Cannot obtain Metadata from http://localhost:49796/Test.svc/GetInformation?memberId=1 If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:49796/Test.svc/GetInformation?memberId=1 Metadata contains a reference that cannot be resolved: 'http://localhost:49796/Test.svc/GetInformation?memberId=1'. The remote server returned an unexpected response: (405) Method Not Allowed. The remote server returned an error: (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

The most surprising part is that it is same even if I create a new service or test an old service. Did something went wrong in my pc globally? It appears to be some file corruption or change in config globally somewhere as all of WCF REST Services in my pc behaves the same. I googled but could not find any proper answer.

I tried removing end point and tested again using Test Client. As test client adds basichttpbinding automatically, it is working fine using test client.

Please advise on the fix, if anyone is aware.

my config looks like below:

<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>

My Service contract is as below

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

I have analyzed further and found that if I change List to string it works fine. I added KnownType as well on top of service contract but it doesn't work. Please advise on this line.

解决方案

The resolution is mind-blowing. I see one of the data contract fields is NULL in the DB but it is not Nullable type in C#. It is resulting in the strange behavior my REST Service.

这篇关于与WCF REST服务奇怪的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆