前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >silverlight向wcf传递大于8192字节(8k)的字符串

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

作者头像
菩提树下的杨过
发布2018-01-23 17:11:19
7170
发布2018-01-23 17:11:19
举报

默认情况下,silverlight在调用wcf时,如果传递的参数长度大于8192字节,即8k,会提示Not Found错误。

解决方法如下:

1、wcf服务端修改web.config 如下:

代码语言:javascript
复制
<?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的代码

代码语言:javascript
复制
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如下:

代码语言:javascript
复制
<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的调用代码

代码语言:javascript
复制
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());
        }
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2011-06-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档