Silverlight连接WCF--错误"远程服务器返回了错误NotFound”

  今天在项目中发送数据包到服务器端,WCF返回错误信息:The remote server returned an error: NotFound. 经过排查,通过以下步骤进行了解决。

  Silverlight企业级项目中,经常要发送大量数据包到服务器端,而WCF服务本身对数据包进行了限制,最大不能超过65535,而我在项目中尝试发送XML大数据包到服务器端,WCF返回以上错误。

  起初考试在客户端尝试重新定义BasicHttpBinding对象

1 Dim binding As BasicHttpBinding = New BasicHttpBinding()
2 
3 binding.MaxBufferSize = 2147483647 
4 binding.MaxReceivedMessageSize = 2147483647
5 

  然后考虑修改ServiceReferences.ClientConfig文件,增加Buffer 尺寸。

<bindings> 
      <basicHttpBinding> 
                <binding name="BasicHttpBinding_IDataService" 
                         maxBufferSize="2147483647" 
                         maxReceivedMessageSize="2147483647"> 
                    <security mode="None" /> 
                </binding> 
       </basicHttpBinding> 
</bindings>

  但是,WCF仍旧报错。

  最后,尝试修改服务器端,在Web.config中添加自定义BasicHttpBinding对象,

<bindings> 
   <basicHttpBinding> 
     <binding name="BasicHttpBinding_IDataService" 
         maxBufferPoolSize="2147483647" 
         maxReceivedMessageSize="2147483647" 
         maxBufferSize="2147483647"> 
       <readerQuotas 
           maxArrayLength="2147483647" 
           maxBytesPerRead="2147483647" 
           maxDepth="2147483647" 
           maxNameTableCharCount="2147483647" 
           maxStringContentLength="2147483647" /> 
     </binding> 
   </basicHttpBinding> 
</bindings>

  另外,在ServiceBehaviors中添加maxItemsInObjectGraph属性

<behaviors> 
<serviceBehaviors> 
  <behavior name="TeacherLogic.Net.Web.DataServiceBehavior"> 
   <serviceMetadata httpGetEnabled="true" /> 
   <serviceDebug includeExceptionDetailInFaults="true" /> 
   <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
  </behavior> 
</serviceBehaviors> 
</behaviors>

  添加自定义Binding对象后,在endpoint中引用,就解决了“NotFound”问题了。

<endpoint address="" binding="basicHttpBinding" contract="Myproject.IDataService" bindingConfiguration="BasicHttpBinding_IDataService"/>

  

      在Silverlight官方论坛还有一种说法,因为404 Notfound错误的,还可能因为跨域问题,这个问题比较容易解决,只要在网站根目录下建立一个clientaccesspolicy.xml文件即可。

 

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值