请有人帮助我找出发生的事情.我有我的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**
...
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
客户端配置(已编辑)
<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>
Run Code Online (Sandbox Code Playgroud)
在我的文件scvlog中,我没有任何异常!我没有任何其他想法我还能做些什么才能理解问题出在哪里.请有人帮帮我!!!
Ric*_*ram 15
一个不同的答案,以防任何人到达这里,因为我一直在寻找问题的一般答案.
似乎执行驴工作的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;
}
Run Code Online (Sandbox Code Playgroud)
并且要使用它,而不是返回一个对象,在调用helper方法之后返回该对象,所以
public MyDodgyObject MyService() {
... do lots of work ...
return myResult;
}
Run Code Online (Sandbox Code Playgroud)
变
public MyDodgyObject MyService() {
... do lots of work ...
return CheckCanSerialize(myResult);
}
Run Code Online (Sandbox Code Playgroud)
然后在服务停止关注之前抛出序列化中的任何错误,因此可以在调试器中进行分析.
注意; 我不建议将调用留在生产代码中,它具有序列化和反序列化对象的开销,一旦代码被调试就没有任何实际好处.
希望这有助于某人 - 我浪费了大约3个小时试图追踪它.
我不知道它是否真的可以作为答案,但我已经尝试将web.config更改为<security mode="None" />,<security mode="Transport" />并且它工作了!!!
我想要注意,这部分应该只在web.config和客户端配置中更改仍然存在<security mode="None" />,因为在两者中运输它不起作用!
所以在那之后,我决定再次回来None security,它工作了几分钟,然后再次停止,它回来了错误:
服务器没有提供有意义的回复; 这可能是由于合同不匹配,过早的会话关闭或内部服务器错误造成的
security mode to Transport就我而言,我正在开发一个与WCF Web服务通信的Windows应用程序项目.Web服务使用netTcpBinding返回一个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")
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52795 次 |
| 最近记录: |