預設情況下,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
05 HTTP://go.microsoft.com/fwlink/?LinkId=169433
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的代碼

 

01 using System.ServiceModel;
02
03 namespace 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的調用代碼

 

01 using System;
02 using System.Windows;
03 using System.Windows.Controls;
04 using WCF_SL_8192.WCF;
05
06 namespace 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 }
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()