由于服务器终节点绑定未使用http协议造成

这个错误之前也遇到过多次 归纳原因有

1、没有重新生成代理文件

2、这是因为WCF返回值无法序列化造成的

针对第一种的解决方法:

用SvcConfigEditor为客户端和服务端都加上一个behavior (服务端添加servicehehavior, 客户端添加endpointbehavior),然后为这两个服务各添加一个dataContractSerializer,把他的maxItemsInObjectGraph字段变成更大的数。

服务端配置:

<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>
针对第二种解决方法:

WCF 不支持返回DataTable,序列化成string类型字符串返回。

在这里祝大家好运!

posted @ 2012-07-11 10:33  ellens  阅读(492)  评论(0)    收藏  举报