WCF ERROR:服务器没有提供有意义的回复; [英] WCF ERROR: The server did not provide a meaningful reply;
问题描述
请有人帮我找出发生了什么.我的 WCF 服务运行良好,现在突然出现此错误:
<块引用>服务器没有提供有意义的回复;这可能是由于合同不匹配、过早的会话关闭或内部服务器错误
我必须说,当我选择数千条记录时它仍然有效,但是当数据很大时,我收到此错误,尽管在它工作正常之前!
private static string ConnString = "Server=127.0.0.1; Port=5432; Database=DBname; User Id=UName; Password=MyPassword;"数据表 myDT = 新数据表();NpgsqlConnection myAccessConn = new NpgsqlConnection(ConnString);myAccessConn.Open();字符串查询 = "SELECT * FROM Twitter";NpgsqlDataAdapter myDataAdapter = new NpgsqlDataAdapter(query, myAccessConn);myDataAdapter.Fill(myDT);foreach(myDT.Rows 中的 DataRow dr){**当我有太多记录时,它会停在这里**...
web.config
<预><代码><配置><system.web><编译调试="false" targetFramework="4.0"/><httpRuntime maxRequestLength="2147483647" executionTimeout="100000"/></system.web><系统诊断><trace autoflush="true"/><来源><源名称="System.ServiceModel"switchValue="信息,活动跟踪"传播活动=真"><听众><add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Traces4.svclog"/></听众></来源></来源></system.diagnostics><system.serviceModel><绑定><基本HttpBinding><绑定名称="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"/><安全模式=无"><transport clientCredentialType="None" proxyCredentialType="None"领域=""/><message clientCredentialType="UserName" algorithmSuite="默认"/></安全></binding></basicHttpBinding></绑定><客户><端点地址="" binding="basicHttpBinding"bindingConfiguration="BasicHttpBinding_IDBService" contract="DBServiceReference.IDBService"name="BasicHttpBinding_IDBService"/></客户端><行为><服务行为><行为名称=""><serviceMetadata httpGetEnabled="true"/><serviceDebug includeExceptionDetailInFaults="true"/><dataContractSerializer maxItemsInObjectGraph="2147483646"/></行为></serviceBehaviors></行为><serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/></system.serviceModel></配置>客户端配置(已修改)
<预><代码><配置><system.serviceModel><绑定><基本HttpBinding><绑定名称="BasicHttpBinding_IRouteService" maxBufferSize="2147483647"maxReceivedMessageSize="2147483647"><安全模式=无"/></binding><绑定名称="BasicHttpBinding_IDBService" closeTimeout="00:30:00"openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"transferMode="缓冲" ><安全模式=无"/></binding></basicHttpBinding><自定义绑定><绑定名称="CustomBinding_IRouteService"><binaryMessageEncoding/><httpTransport maxReceivedMessageSize="2147483647"maxBufferSize="2147483647"/></binding></customBinding></绑定><客户><端点地址="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc"binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"contract="BingRoutingService.IRouteService" name="BasicHttpBinding_IRouteService"/><端点地址="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/binaryHttp"binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"contract="BingRoutingService.IRouteService" name="CustomBinding_IRouteService"/><端点地址="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDBService"contract="DBServiceReference.IDBService" name="BasicHttpBinding_IDBService"/></客户端></system.serviceModel></配置>在我的文件 scvlog 中,我没有发现任何异常!我不知道我还能做些什么来了解问题出在哪里.请有人帮助我!!!
一个不同的答案,以防万一有人到达这里,因为我正在寻找问题的一般答案.
似乎执行驴工作的 DataContractSerializer 非常挑剔,但并不总是将真正的错误传递给客户端.服务器进程在失败后立即终止 - 因此找不到错误.在我的例子中,问题是一个用作标志的枚举,但没有用 [Flags] 属性装饰(挑剔或什么!).
为了解决这个问题,我创建了一个序列化程序的实例并检查了调试器中的错误;这是一个代码片段,因为我手头有它.
响应评论中的请求......
修改了代码片段以显示我现在使用的辅助方法.与以前大致相同,但使用了方便的通用包装器.
public static T CheckCanSerialize(this T returnValue) {var lDCS = new System.Runtime.Serialization.DataContractSerializer(typeof(T));字节[] lBytes;使用 (var lMem1 = new IO.MemoryStream()) {lDCS.WriteObject(lMem1, returnValue);lBytes = lMem1.ToArray();}TlResult;使用 (var lMem2 = new IO.MemoryStream(lBytes)) {lResult = (T)lDCS.ReadObject(lMem2);}返回 lResult;}
而要使用这个,不是返回一个对象,而是在调用辅助方法后返回该对象,所以
public MyDodgyObject MyService() {......做很多工作......返回我的结果;}
变成
public MyDodgyObject MyService() {......做很多工作......返回 CheckCanSerialize(myResult);}
序列化中的任何错误都会在服务停止关注之前抛出,因此可以在调试器中进行分析.
注意;我不建议将调用留在生产代码中,它具有序列化和反序列化对象的开销,一旦代码被调试就没有任何实际好处.
希望这对某人有所帮助 - 我浪费了大约 3 个小时试图追踪它.
please somebody can help me to find out what is happened. I have my WCF service which worked fine, and now suddenly I have this error:
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error
I must tell that it still works when I select some thousands of records, but when the data is huge I receive this error, although before it worked fine!
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>
client config (Edited)
<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>
In my file scvlog I don' t get any exception! I don't have any other idea what else I can do for understand where is the problem. Please somebody help me!!!
A different answer, just in case anyone arrives here as I did looking for a general answer to the question.
It seems that the DataContractSerializer that does the donkey-work is incredibly finicky, but doesn't always pass the real error to the client. The server process dies straight after the failure - hence no error can be found. In my case the problem was an enum that was used as flags, but not decorated with the [Flags] attribute (picky or what!).
To solve it I created an instance of the serializer and inspected the error in the debugger; here's a code snippet since I have it to hand.
EDIT: In response to request in comments ...
Amended the code snippet to show the helper method I now use. Much the same as before, but in a handy generic wrapper.
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;
}
And to use this, instead of returning an object, return the object after calling the helper method, so
public MyDodgyObject MyService() {
... do lots of work ...
return myResult;
}
becomes
public MyDodgyObject MyService() {
... do lots of work ...
return CheckCanSerialize(myResult);
}
Any errors in serialization are then thrown before the service stops paying attention, and so can be analysed in the debugger.
Note; I wouldn't recommend leaving the call in production code, it has the overhead of serializing and deserializing the object, without any real benefit once the code is debugged.
Hope this helps someone - I've wasted about 3 hours trying to track it down.
这篇关于WCF ERROR:服务器没有提供有意义的回复;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!