Silverlight 调用WCF常见错误

 

错误1 

错误描述:The remote server returned an error: NotFound

可能原因:WCF服务本身对数据包进行了限制,最大不能超过65535,Silverlight发送大数据包到服务器端(例如图片直接存于数据库),   WCF返回以上错误。

传输时,最好用List<string> 代替 string做参数。

解决方法:

(1)修改Silverlight端ServiceReferences.ClientConfig文件,增加Buffer 尺寸。
  <bindings> 
      <basicHttpBinding> 
                <binding name="BasicHttpBinding_IDataService" 
                         maxBufferSize="2147483647" 
                         maxReceivedMessageSize="2147483647"> 
                    <security mode="None" /> 
                </binding> 
       </basicHttpBinding> 
</bindings>

 

         System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.None);
            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.MaxBufferSize = int.MaxValue;
            binding.ReceiveTimeout = TimeSpan.FromMinutes(5);
            binding.SendTimeout = TimeSpan.FromMinutes(5);
            binding.CloseTimeout = TimeSpan.FromMinutes(5);
            binding.OpenTimeout = TimeSpan.FromMinutes(5);
            EndpointAddress ep = new EndpointAddress("../DataService.svc");
            MyTest.DataService.DataServiceClient client = new DataServiceClient(binding,ep);

(2)修改服务器端,在Web.config中添加自定义BasicHttpBinding对象,
 

 服务器端:web.config

<configuration>
  <appSettings>
    <add key="ReturnTablePath" value="C:\TestData\test_data.csv"/>
  </appSettings>
    <system.web>
      <httpRuntime maxRequestLength="2147483647"/>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>

  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <behaviors>
      <serviceBehaviors>
        <behavior name="MappingDataEditor.Web.DataServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="MappingDataEditor.Web.DataServiceBehavior" name="MappingDataEditor.Web.DataService">
        <!--name=命名空间(ExcelServer)+类名(Server1)-->
        <endpoint address="" bindingConfiguration="LargeBuffer" binding="basicHttpBinding" contract="MappingDataEditor.Web.IDataService"/>
        <!--contract=命名空间(ExcelServer)+接口(IServer1)-->
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="LargeBuffer" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <!--name=随意命名-->
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
          <security mode="None"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

错误2

 

Silverlight wcf 上传大数据

 

1.服务端:

 MaxRequestLength:  请求的最大大小(以千字节为单位)。默认大小为 4096 KB (4 MB)。

<system.web>
  <httpRuntime maxRequestLength="2147483647"/>
  <compilation debug="true" targetFramework="4.0" />
 </system.web>

 

 

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="NewBinding2MB" maxReceivedMessageSize="2147483647"
                         maxBufferSize="2147483647"  maxBufferPoolSize="2147483647"
                         closeTimeout="10:00:00" openTimeout="10:00:00" receiveTimeout="10:00:00"
                         sendTimeout="10:00:00" >
                    <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"
                                  maxBytesPerRead="2147483647" maxDepth="2147483647"      

                                  maxNameTableCharCount="2147483647" />
                </binding>
            </basicHttpBinding>
        </bindings>

 

 

2.客户端

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

 

时间: 2024-09-19 09:33:43

Silverlight 调用WCF常见错误的相关文章

Silverlight调用WCF如何处理错误

Silverilght 客户端不支持 FaultException. 只会显示一个 404 错误.所 以,服务端抛出的异常,在客户端是无法直接通过序列化 /反序列化传递得到的 .但是可以改用下列一些方法来帮助从客户端得到错误信息: 1. 在 Service 端,将返回值对象重新设计,在其中添加错误信息的字段, 传递回来. 2. 在 Service 端发生异常时,捕获之,并使用 Session 存储(同时可以做 日志),然后结果里 return false. Silverlight里判断返回 fa

Silverlight 调用 WCF 如何处理错误

Silverilght 客户端不支持 FaultException. 只会显示一个 404 错误.所以,服务端抛出的异常,在客户端是无法直接通过序列化 /反序列化传递得到的.但是可以改用下列一些方法来帮助从客户端得到错误信息: 1. 在 Service 端,将返回值对象重新设计,在其中添加错误信息的字段,传递回来. 2. 在 Service 端发生异常时,捕获之,并使用 Session 存储(同时可以做日志),然后结果里 return false. Silverlight里判断返回 false

silverlight调用wcf后无法执行

问题描述 silverlight调用wcf后无法执行 private void LayoutRoot_Loaded(object sender, RoutedEventArgs e) { platformClient = new PlatformDB.PlatformDBClient(); platformClient.GetEntityDataCompleted += new EventHandler(platformClient_GetEntityDataCompleted); platfo

Silverlight + WCF常见错误调试方法

1. 404 Not Found a. 检查服务器是否放了 ClientAccessPolicy.xml 文件.内容范例如下: <?xml version="1.0" encoding="utf-8" ?><access- policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <do

ASP中数据库调用中常见错误的现象和解决方法

不能打开注册表关键字(8007000e) Microsoft OLE DB Provider for ODBC Drivers 错误 '8007000e' [Microsoft][ODBC Microsoft Access Driver]常见错误 不能打开注册表关键字 'Temporary (volatile) Jet DSN for process 0x11b4 Thread 0x1a4c DBC 0x9d34354 Jet'. 1.打开数据库时写法不对,标准的ACCESS数据库调用写法: "

ASP中数据库调用中常见错误的现象和解决

 下面是虚机维护中,经常碰到的一些ASP程序中的数据库调用的错误,现收集整理如下: 不能打开注册表关键字(8007000e) Microsoft OLE DB Provider for ODBC Drivers 错误 '8007000e' [Microsoft][ODBC Microsoft Access Driver]常见错误 不能打开注册表关键字 'Temporary (volatile) Jet DSN for process 0x11b4 Thread 0x1a4c DBC 0x9d34

使用Task简化Silverlight调用Wcf

原文http://www.cnblogs.com/lemontea/archive/2012/12/09/2810549.html 从.Net4.0开始,.Net提供了一个Task类来封装一个异步操作,用来简化异步 方法的调用..Net4.5更进一步,添加了async和await两个关键字,异步编程同步化,不用再写一堆散乱的回调或者完成事件处理. Silverlight5开始支持Task类,但是要用await的话就需要编译器的支持,VS2012直接支持,如果是VS2010,那就要安装Async

silverlight调用wcf服务

问题描述 在silverlight中调用wcf服务得到异步操作的结果为什么e.Rusult的值会ArrayOfElement,我在wcf中返回的是一个list<T>类型的,ArrayOfElement是什么类型啊,它总是提示无法将类型ArrayOfElement饮食转换为System.collection.IEnumerable,求解啊

Silverlight与WCF之间的通信(4)

silverlight以net.tcp方式调用console上寄宿的wcf服务 (由于最近是针对一个demo进行的研究,在之前公开过代码结构,这里只是对需要改动的地方加以说 明)WCF4.0使得编写wcf服务不再那么复杂,去掉了许多的配置信息,客户端只需要一个服务地址,便可 在系统生成的代理类下做开发了,在部署时也只需要更改引用配置文件的地址即可.但是今天我尝试 silverlight以net.tcp方式连接host到console上的wcf服务时,却颇费周折,一个wcf console ser