webservice的TTP 响应时发生错误,可能是由于服务终结点绑定未使用 HTTP 协议造成的,解决办法

webservice调用异常,报错信息:接收对 http://www.bubuko.com/bubuko.asmx 的  HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。

解决办法之一:

用SvcConfigEditor为客户端和服务端都加上一个behavior (服务端添加servicehehavior, 客户端添加endpointbehavior),然后为这两个服务各添加一个dataContractSerializer,把他的maxItemsInObjectGraph字段变成更大的数。我已经调试通过你的代码了。

这里是我这里服务端添加的log:
<system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
        logMessagesAtTransportLevel="true" />
    </diagnostics>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/ContactManager/md" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="65536000" />        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="NewBehavior" name="WcfServiceLibrary1.ContactManager">
        <endpoint address="http://localhost:8000/ContactManager" binding="wsHttpBinding"
          bindingConfiguration="NewBindingStationCnfg" contract="WcfServiceLibrary1.IContactManager" />
        <endpoint address="http://localhost:8000/ContactManager/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="NewBindingStationCnfg" maxReceivedMessageSize="483647" />
      </wsHttpBinding>

    </bindings>
  </system.serviceModel>


这里是我客户端的config:

    <system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="NewBehavior">
                    <dataContractSerializer maxItemsInObjectGraph="6553600" />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <diagnostics>
            <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
                logMessagesAtTransportLevel="true" />
        </diagnostics>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IContactManager1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8000/ContactManager" behaviorConfiguration="NewBehavior"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IContactManager1"
                contract="ServiceReference2.IContactManager" name="WSHttpBinding_IContactManager1">
                <identity>
                    <userPrincipalName value="vblab1@redmond.corp.microsoft.com" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

webservice的TTP 响应时发生错误,可能是由于服务终结点绑定未使用 HTTP 协议造成的,解决办法

上一篇:windows下编译tensorflow2.5.0 c++库并调用


下一篇:【JAVA编码】 JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换