23

请有人可以帮我找出发生了什么。我的 WCF 服务运行良好,现在突然出现此错误:

服务器没有提供有意义的回复;这可能是由合同不匹配、会话过早关闭或内部服务器错误引起的

我必须告诉我,当我选择数千条记录时它仍然有效,但是当数据很大时,我收到这个错误,虽然之前它工作正常!

    private static string ConnString = "Server=127.0.0.1; Port=5432; Database=DBname; User Id=UName; Password=MyPassword;"
    DataTable myDT = new DataTable();

                NpgsqlConnection myAccessConn = new NpgsqlConnection(ConnString);
                myAccessConn.Open();
        string query = "SELECT * FROM Twitter";

                NpgsqlDataAdapter myDataAdapter = new NpgsqlDataAdapter(query, myAccessConn);

                myDataAdapter.Fill(myDT);
                foreach (DataRow dr in myDT.Rows)
                {
   **WHEN I HAVE TOO MANY RECORDS IT STOPS HERE**
        ...

网络配置

<configuration>
    <system.web>
        <compilation debug="false" targetFramework="4.0" />
      <httpRuntime maxRequestLength="2147483647" executionTimeout="100000" />
    </system.web>
  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Traces4.svclog"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IDBService" closeTimeout="00:30:00"
                    openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
    <client>
      <endpoint address="" binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_IDBService" contract="DBServiceReference.IDBService"
          name="BasicHttpBinding_IDBService" />
    </client>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                  <serviceMetadata httpGetEnabled="true" />
                  <serviceDebug includeExceptionDetailInFaults="true" />
                  <dataContractSerializer maxItemsInObjectGraph="2147483646" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>

客户端配置(已编辑)

<configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IRouteService" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                    </binding>
                    <binding name="BasicHttpBinding_IDBService" closeTimeout="00:30:00"
                        openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
                        maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
                        transferMode="Buffered" >

                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
                <customBinding>
                    <binding name="CustomBinding_IRouteService">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647"
                            maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>

            <client>
                <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"
                    contract="BingRoutingService.IRouteService" name="BasicHttpBinding_IRouteService" />
                <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/binaryHttp"
                    binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"
                    contract="BingRoutingService.IRouteService" name="CustomBinding_IRouteService" />
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDBService"
                    contract="DBServiceReference.IDBService" name="BasicHttpBinding_IDBService" />
            </client>
        </system.serviceModel>
    </configuration>

在我的文件scvlog 中,我没有得到任何异常!我不知道我还能做些什么来了解问题出在哪里。请有人帮助我!!!

4

10 回答 10

21

一个不同的答案,以防万一有人像我一样来到这里寻找问题的一般答案。

似乎完成驴工作的 DataContractSerializer 非常挑剔,但并不总是将真正的错误传递给客户端。服务器进程在失败后直接死亡 - 因此找不到错误。在我的情况下,问题是一个用作标志的枚举,但没有用 [Flags] 属性装饰(挑剔或什么!)。

为了解决这个问题,我创建了一个序列化程序的实例并检查了调试器中的错误;这是一个代码片段,因为我手头有它。

编辑:响应评论中的请求...

修改了代码片段以显示我现在使用的辅助方法。和以前一样,但在一个方便的通用包装器中。

public static T CheckCanSerialize<T>(this T returnValue) {
    var lDCS = new System.Runtime.Serialization.DataContractSerializer(typeof(T));

    Byte[] lBytes;
    using (var lMem1 = new IO.MemoryStream()) {
        lDCS.WriteObject(lMem1, returnValue);
        lBytes = lMem1.ToArray();
    }

    T lResult;
    using (var lMem2 = new IO.MemoryStream(lBytes)) {
        lResult = (T)lDCS.ReadObject(lMem2);
    }

    return lResult;
}

而要使用这个,不是返回一个对象,而是在调用辅助方法后返回对象,所以

public MyDodgyObject MyService() {
    ... do lots of work ...
    return myResult;
}

变成

public MyDodgyObject MyService() {
    ... do lots of work ...
    return CheckCanSerialize(myResult);
}

然后在服务停止关注之前抛出序列化中的任何错误,因此可以在调试器中进行分析。

笔记; 我不建议将调用留在生产代码中,它具有序列化和反序列化对象的开销,一旦调试代码就没有任何真正的好处。

希望这对某人有所帮助-我已经浪费了大约 3 个小时来尝试追踪它。

于 2014-04-14T18:27:31.267 回答
8

我不知道这是否真的可以成为答案,但我试图将web.config<security mode="None" />to更改为<security mode="Transport" />它工作!

我想注意这部分应该只在web.config和客户端配置中更改<security mode="None" />,因为在这两个中都有 Transport 它不起作用!

所以在那之后,我决定尝试再次回到None security它,它工作了几分钟,然后又停止了,它又出现了错误:

服务器没有提供有意义的回复;这可能是由合同不匹配、会话过早关闭或内部服务器错误引起的

所以看来我的解决方案是在 web.config 中设置

security mode to Transport

于 2013-04-24T07:21:46.767 回答
5

就我而言,我正在开发一个与 WCF Web 服务通信的 Windows 应用程序项目。使用 netTcpBinding 的 Web 服务正在返回一个 Stream 对象(图片)。

由于 windows 应用程序没有配置文件,因此使用默认值进行绑定。只需在客户端后端代码上扩展 MaxReceivedMessageSize 即可解决我的问题。

var API = new StreamService.StreamServiceClient(
  new System.ServiceModel.NetTcpBinding(System.ServiceModel.SecurityMode.None)
  {
    MaxReceivedMessageSize = 2147483647
  },
  new System.ServiceModel.EndpointAddress("net.tcp://machine/app/service.svc")
);
于 2015-07-03T10:26:06.670 回答
3

有时,此问题是由由于绑定中的默认值而被剪切的过大消息引起的。

您应该在 app.config 文件中的绑定中添加具有足够大值的maxReceivedMessageSize、maxBufferPoolSize 和 maxBufferSize - 这应该可以解决问题:)

例子:

<bindings>
<netTcpBinding>
<binding 
name="ExampleBinding" closeTimeout="00:01:00"
maxReceivedMessageSize="73400320"
maxBufferPoolSize="70000000"
maxBufferSize="70000000"/>
</netTcpBinding>
</bindings>

祝你好运!

于 2016-09-29T07:50:14.650 回答
2

就我而言,我正在开发一个 MVC 应用程序并且我已经改变了

maxReceivedMessageSize ="10000000"

maxReceivedMessageSize ="70000000"

它奏效了!是因为来自网络服务器的响应超过了maxReceivedMessageSize ="10000000"
所以我增加 maxReceivedMessageSizemaxReceivedMessageSize ="70000000"

于 2016-12-28T19:15:58.870 回答
1

根据我对这个错误的经验,只需检查服务主机的事件日志,看看实际的根异常是什么。

于 2015-08-03T15:26:39.923 回答
0

对我来说,这是一个从数据库中检索到的项目的延迟加载列表。

WCF 接收器将尝试迭代它们,这将尝试转到数据库,这显然无法工作。

于 2014-12-05T16:38:12.463 回答
0

在 BizTalk 中,我们使用来解决此问题。

大多数情况下,由于来自服务的消息的大小,会发生此问题。所以我们需要将接收消息的大小从 65,356 增加到 2,365,60。它对我有用。

在此处输入图像描述

于 2017-01-16T16:13:33.253 回答
0

就我而言,从 .NET Framework 4.5 升级到 .NET Framework 4.8 后,我必须删除用 DataMemberAttribute 修饰的属性的只读修饰符。

于 2021-06-29T00:43:29.347 回答
0

ASP.NET 应用程序可以使用发出请求的用户的 Windows 身份(用户帐户)执行。模拟通常用于依赖 Microsoft Internet 信息服务 (IIS) 对用户进行身份验证的应用程序中。默认情况下禁用 ASP.NET 模拟。

启用此功能,您的 API 将开始工作 - 它在 IIS 身份验证中

于 2019-06-23T07:55:42.107 回答