silverlight向wcf传递大于8192字节(8k)的字符串
默认情况下,silverlight在调用wcf时,如果传递的参数长度大于8192字节,即8k,会提示Not Found错误。
解决方法如下:
1、wcf服务端修改web.config 如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <? xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> < configuration > < system.web > < compilation debug="true" targetFramework="4.0" /> </ system.web > < system.serviceModel > < behaviors > < serviceBehaviors > <!--注:此处的name值要跟下面的behaviorConfiguration值对应--> < behavior name="A"> < serviceMetadata httpGetEnabled="true"/> < serviceDebug includeExceptionDetailInFaults="false"/> < dataContractSerializer maxItemsInObjectGraph="2147483647"/> </ behavior > </ serviceBehaviors > </ behaviors > < services > <!--注1:此处的behaviorConfiguration值要跟上面的name值对应--> <!--注2:此处的name值不能随便修改,命名格式为:完全命名空间+类名 --> < service behaviorConfiguration="A" name="WCF_SL_8192.Web.WCF.HelloWorld"> <!--注1:此处的contract值不能随便修改,命名格式为:完全命名空间+类名 --> <!--注2:此处的bindingConfiguration值要与下面 binding name中的name值对应--> < endpoint address="" bindingConfiguration="BBB" binding="basicHttpBinding" contract="WCF_SL_8192.Web.WCF.HelloWorld"/> </ service > </ services > < bindings > < basicHttpBinding > < binding name="BBB" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <!--name=随意命名,但要与上面的bindingConfiguration="BBB"对应 --> < readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/> < security mode="None"></ security > </ binding > </ basicHttpBinding > </ bindings > </ system.serviceModel > </ configuration > |
附:wcf的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | using System.ServiceModel; namespace WCF_SL_8192.Web.WCF { [ServiceContract] public class HelloWorld { [OperationContract] public int Test( string msg) { return msg.Length; } } } |
2、SL端修改ClientConfig如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | < configuration > < system.serviceModel > < bindings > < basicHttpBinding > < binding name="BasicHttpBinding_HelloWorld" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> < security mode="None" /> </ binding > </ basicHttpBinding > <!--下面这个节点是关键--> < customBinding > < binding name="BasicHttpBinding_HelloWorld"> < textMessageEncoding messageVersion="Default" writeEncoding="utf-8" /> < httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" /> </ binding > </ customBinding > </ bindings > < client > < endpoint address="http://localhost:1588/WCF/HelloWorld.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_HelloWorld" contract="WCF.HelloWorld" name="BasicHttpBinding_HelloWorld" /> </ client > </ system.serviceModel > </ configuration > |
附:SL的调用代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | using System; using System.Windows; using System.Windows.Controls; using WCF_SL_8192.WCF; namespace WCF_SL_8192 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); this .Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded( object sender, RoutedEventArgs e) { HelloWorldClient client = new HelloWorldClient(); client.TestCompleted += new EventHandler<TestCompletedEventArgs>(client_TestCompleted); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for ( int i = 0; i < 100000; i++) { sb.Append( "A" ); } client.TestAsync(sb.ToString()); } void client_TestCompleted( object sender, TestCompletedEventArgs e) { MessageBox.Show(e.Result.ToString()); } } } |
作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
2010-06-29 Silverlight:Mouse Avoiding 躲避鼠标效果