WCF这可能是由于服务端点绑定未使用HTTP协议造成的

WCF这可能是由于服务端点绑定未使用HTTP协议造成的,wcf,wcf-data-services,wcf-binding,httpresponse,json-deserialization,Wcf,Wcf Data Services,Wcf Binding,Httpresponse,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

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)) 
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;
}
public IList JsonDeserializeFromDatabase(字符串值)
{
MemoryStream ms=新的MemoryStream(Encoding.ASCII.GetBytes(value));
DataContractJsonSerializer ser=新的DataContractJsonSerializer(类型(列表));
IList tableData=(IList)ser.ReadObject(ms);
Close女士();
Dispose女士();
返回表格数据;
}
IService1.cs

[OperationContract]
IList<Person> JsonDeserializeFromDatabase(string value);
[运营合同]
IList JSO数据库(字符串值);
服务器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>
    <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">

...
客户端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>
    <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">

异常信息
-类型:System.ServiceModel.CommunicationException,System.ServiceModel,版本=4.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089
-消息:接收对~Service1.svc的HTTP响应时出错。这可能是由于服务端点绑定未使用HTTP协议造成的。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志

我从服务器跟踪查看器获得了此异常信息,所以请不要建议我放置标签。

如你所见,我增加了所有的尺寸。

喜欢我不知道为什么在调用JsonDeserializeFromDatabase(stream)时出错。

“接收对~~~~~~/Service1.svc的HTTP响应时出错。这可能是由于服务端点绑定未使用HTTP协议。这也可能是由于服务器中止了HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。”

我在WCF服务中从数据库返回记录时也遇到过此错误消息。除了在客户端配置(App.config)中的绑定中增加maxReceivedMessageSize外,另一个问题似乎是,如果实体框架对象的关系导致其对象图中的循环,则WCF序列化实体框架对象时会遇到问题

我通过返回buddy类对象(它是原始数据库记录的副本,但没有任何关系链接)而不是原始数据库类本身来解决这个问题

希望这有帮助-
为什么微软不能产生更好的错误信息??在这里,与许多其他情况一样,错误消息没有给出真正问题的线索(WCF调用返回值的序列化)

re:WCF&如果实体框架对象的关系导致其对象图中的循环,则序列化实体框架对象时会出现问题。我得到了相同的错误和user1956642提供的答案,它确实为我指明了正确的方向,但后来意识到我可以通过配置DbContext来序列化这些实体

context.Configuration.ProxyCreationEnabled = false;

延迟加载仍然启用,但我相信动态代理用于更改跟踪和延迟加载。所以是的。。。仅我的5c

尝试使用byte[]作为流参数(序列化/反序列化)