Adr*_*ian 2 wcf httpresponse wcf-binding wcf-data-services json-deserialization
Default.aspx.cs
WCFService.Service1Client client = new WCFService.Service1Client();
string stream = client.JsonSerializeFromDatabase();
client.Close();
WCFService.Service1Client client2 = new WCFService.Service1Client();
foreach (WCFService.Person in client2.JsonDeserializeFromDatabase(stream))
Run Code Online (Sandbox Code Playgroud)
Service1.svc.cs
public IList<Person> JsonDeserializeFromDatabase(string value)
{
MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(value));
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<Person>));
IList<Person> tableData = (IList<Person>)ser.ReadObject(ms);
ms.Close();
ms.Dispose();
return tableData;
}
Run Code Online (Sandbox Code Playgroud)
IService1.cs
[OperationContract]
IList<Person> JsonDeserializeFromDatabase(string value);
Run Code Online (Sandbox Code Playgroud)
服务器Web.config
<httpRuntime maxRequestLength="8192"/>
</system.web>
...
<system.serviceModel>
<services>
<service name="TestWCF.Service1" behaviorConfiguration="TestWCF.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" contract="TestWCF.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TestWCF.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
Run Code Online (Sandbox Code Playgroud)
客户端Web.config
<httpRuntime maxRequestLength="8192"/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="debuggingBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:50:00" openTimeout="00:50:00" receiveTimeout="00:50:00" sendTimeout="00:50:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<reliableSession ordered="true" inactivityTimeout="00:50:00" enabled="false"/>
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="~~~~~/Service1.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1" contract="WCFService.IService1" name="WSHttpBinding_IService1" behaviorConfiguration="debuggingBehaviour">
Run Code Online (Sandbox Code Playgroud)
异常信息
- 类型:System.ServiceModel.CommunicationException,System.ServiceModel,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089
- 消息:接收到~~~~~/Service1.svc的HTTP响应时发生错误.这可能是由于服务端点绑定不使用HTTP协议.这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭).请参阅服务器日志以获取更多详
我从服务器跟踪查看器中获取了此异常信息,因此请不要建议我输入<-system.diagnostics->标记.
如你所见,我增加了所有大小的东西.
喜欢..我不知道为什么我在调用JsonDeserializeFromDatabase(stream)时出错.
"收到对~~~~~/Service1.svc的HTTP响应时发生错误.这可能是由于服务端点绑定不使用HTTP协议.这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭).有关详细信息,请参阅服务器日志."
从WCF服务中的数据库返回记录时,我也遇到过此错误消息.除了在客户端配置(App.config)中增加绑定中的maxReceivedMessageSize之外,一个单独的问题似乎是如果WCF具有导致其对象图中的循环的关系,则序列化实体框架对象会出现问题.
我通过返回伙伴类对象(它是原始数据库记录的副本,但没有任何关系链接)而不是原始数据库类本身来解决这个问题.
希望这会有所帮助 - 为什么微软不会产生更好的错误信息?在这里,与许多其他情况一样,错误消息不能解决真正的问题(从WCF调用返回值的序列化)!
| 归档时间: |
|
| 查看次数: |
29070 次 |
| 最近记录: |