WCF错误:服务器未提供有意义的答复;

WCF错误:服务器未提供有意义的答复;,wcf,Wcf,请有人能帮我找出发生了什么事。我的WCF服务运行良好,现在突然出现以下错误: 服务器没有提供有意义的回复;这可能是由于契约不匹配、会话过早关闭或内部错误导致的 服务器错误 我必须告诉你,当我选择数千条记录时,它仍然有效,但是当数据量很大时,我收到了这个错误,尽管在它工作正常之前 private static string ConnString = "Server=127.0.0.1; Port=5432; Database=DBname; User Id=UName; Password=

请有人能帮我找出发生了什么事。我的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**
        ...
web.config

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

客户端配置(已编辑)


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

我不知道这是否真的可以作为一个答案,但我已经尝试将web.config中的
更改为
,并且成功了

我想注意的是,这一部分应该只在web.config中更改,而在客户端配置中仍然保持
,因为在这两种情况下传输都不起作用

因此,在那之后,我决定再次尝试返回到
无安全性
,它工作了几分钟,然后再次停止,返回错误:

服务器没有提供有意义的回复;这可能是由于契约不匹配、会话过早关闭或内部服务器错误造成的

因此,在我的例子中,解决方案似乎是在web.config中设置
安全模式传输
一个不同的答案,以防有人像我一样来这里寻找问题的一般答案

似乎完成这项工作的DataContractSerializer非常挑剔,但并不总是将真正的错误传递给客户端。服务器进程在发生故障后立即死亡,因此找不到错误。在我的例子中,问题是一个用作标志的枚举,但没有用[flags]属性修饰(picky之类的!)

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

编辑:响应评论中的请求

修改了代码片段以显示我现在使用的helper方法。与以前大致相同,但使用了一个方便的通用包装器

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 CheckCanSerialize(myResult);
}
序列化中的任何错误都会在服务停止注意之前抛出,因此可以在调试器中进行分析

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


希望这对某人有所帮助-我花了大约3个小时试图找到它。

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


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

在我的例子中,我正在处理一个与WCF Web服务通信的windows应用程序项目。 使用netTcpBinding的web服务正在返回一个流对象(图片)

由于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")
);

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

有时,此问题是由于绑定中的默认值导致消息过大而导致的

您应该在app.config文件中的绑定中添加一些足够大的值,如maxReceivedMessageSize、maxBufferPoolSize和maxBufferSize,这应该可以做到:)

例如:

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


祝你好运

在我的例子中,我正在开发一个MVC应用程序,我已经改变了

maxReceivedMessageSize ="10000000"

成功了!这是因为来自web服务器的响应超过了
maxReceivedMessageSize=“10000000”


因此,我将用于解决此问题的BizTalk中的
maxReceivedMessageSize
增加到
maxReceivedMessageSize=“7000000”

大多数情况下,问题的发生是由于来自服务的消息的大小。因此,我们需要将接收消息的大小从65356增加到2365,60。这对我有用


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


启用此选项,您的API将开始工作-它处于IIS身份验证中

这是完整的web.config。。。?!我看不到
系统。serviceModel/services/service
部分。是的,我需要查看更多配置。然而,由于有这么多可能的记录,你可能有一个超时问题,因为错误,我已经编辑了客户端
<bindings>
<netTcpBinding>
<binding 
name="ExampleBinding" closeTimeout="00:01:00"
maxReceivedMessageSize="73400320"
maxBufferPoolSize="70000000"
maxBufferSize="70000000"/>
</netTcpBinding>
</bindings>
maxReceivedMessageSize ="10000000"
maxReceivedMessageSize ="70000000"