[转]silverlight向wcf传递大于8192字节(8k)的字符串

默认情况下,silverlight在调用wcf时,如果传递的参数长度大于8192字节,即8k,会提示Not Found错误。
解决方法如下:
1、wcf服务端修改web.config 如下:
01<?xml version="1.0"?>
02  
03<!--
04  For more information on how to configure your ASP.NET application, please visit
06  -->
07  
08<configuration>
09    <system.web>
10        <compilation debug="true" targetFramework="4.0" />
11    </system.web>
12  <system.serviceModel>
13    <behaviors>
14      <serviceBehaviors>
15        <!--注:此处的name值要跟下面的behaviorConfiguration值对应-->
16        <behavior name="A">
17          <serviceMetadata httpGetEnabled="true"/>
18          <serviceDebug includeExceptionDetailInFaults="false"/>
19          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
20        </behavior>
21      </serviceBehaviors>
22    </behaviors>
23    <services>
24      <!--注1:此处的behaviorConfiguration值要跟上面的name值对应-->
25      <!--注2:此处的name值不能随便修改,命名格式为:完全命名空间+类名 -->
26      <service behaviorConfiguration="A" name="WCF_SL_8192.Web.WCF.HelloWorld">
27        <!--注1:此处的contract值不能随便修改,命名格式为:完全命名空间+类名 -->
28        <!--注2:此处的bindingConfiguration值要与下面 binding name中的name值对应-->
29        <endpoint address="" bindingConfiguration="BBB" binding="basicHttpBinding" contract="WCF_SL_8192.Web.WCF.HelloWorld"/>      
30      </service>
31    </services>
32    <bindings>
33      <basicHttpBinding>
34        <binding name="BBB" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
35          <!--name=随意命名,但要与上面的bindingConfiguration="BBB"对应 -->
36          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
37          <security mode="None"></security>
38        </binding>
39      </basicHttpBinding>
40    </bindings>
41  </system.serviceModel>
42</configuration>
附:wcf的代码
01using System.ServiceModel;
02  
03namespace WCF_SL_8192.Web.WCF
04{
05    [ServiceContract]
06    public class HelloWorld
07    {
08        [OperationContract]
09        public int Test(string msg)
10        {
11            return msg.Length;
12        }
13    }
14}
2、SL端修改ClientConfig如下:
01<configuration>
02  <system.serviceModel>
03    <bindings>
04      <basicHttpBinding>
05        <binding name="BasicHttpBinding_HelloWorld" maxBufferSize="2147483647"
06             maxReceivedMessageSize="2147483647">
07          <security mode="None" />
08        </binding>
09      </basicHttpBinding>
10      <!--下面这个节点是关键-->
11      <customBinding>
12        <binding name="BasicHttpBinding_HelloWorld">
13          <textMessageEncoding messageVersion="Default" writeEncoding="utf-8" />
14          <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
15        </binding>
16      </customBinding>
17    </bindings>
18    <client>
19      <endpoint address="http://localhost:1588/WCF/HelloWorld.svc"
20          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_HelloWorld"
21          contract="WCF.HelloWorld" name="BasicHttpBinding_HelloWorld" />
22    </client>
23  </system.serviceModel>
24</configuration>
附:SL的调用代码
01using System;
02using System.Windows;
03using System.Windows.Controls;
04using WCF_SL_8192.WCF;
05  
06namespace WCF_SL_8192
07{
08    public partial class MainPage : UserControl
09    {
10        public MainPage()
11        {
12            InitializeComponent();
13  
14            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
15  
16  
17        }
18  
19        void MainPage_Loaded(object sender, RoutedEventArgs e)
20        {
21            HelloWorldClient client = new HelloWorldClient();           
22            client.TestCompleted += new EventHandler<TestCompletedEventArgs>(client_TestCompleted);
23            System.Text.StringBuilder sb = new System.Text.StringBuilder();
24            for (int i = 0; i < 100000; i++)
25            {
26                sb.Append("A");
27            }
28            client.TestAsync(sb.ToString());
29        }
30  
31        void client_TestCompleted(object sender, TestCompletedEventArgs e)
32        {
33            MessageBox.Show(e.Result.ToString());
34        }
35    }
36}

转载于:https://www.cnblogs.com/wohenxinwei/archive/2011/07/11/2102786.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值