none
Silverlight 与 WCF 超时问题 RRS feed

  • 问题

  • 在Silverlight 中调用WCF服务,由于WCF服务执行过程比较长,约2分钟,但在Silverlight中出现超时错误。请问如何处理?

    绑定如下:

                    <binding name="CustomBinding_OutPutService">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>

    环境:VS.Net 2008 C# ;XP SP2;Silverlight 3;IIS6;

    例如:

    服务器

        [ServiceContract(Namespace = "")]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class Service1
        {
            [OperationContract]
            public string DoWork()
            {
                DateTime time = DateTime.Now;
                Thread.Sleep(100000);
                DateTime time1 = DateTime.Now;
                string str = time.ToLongTimeString() + "-" + time.Millisecond + " to " + time1.ToLongTimeString() + "-" + time1.Millisecond;
                return str;
            }

        }

    Client(Silverlight)

                    wcfClient = new SilverlightApplication1.WCF.Service1Client();
                    wcfClient.DoWorkCompleted += new EventHandler<SilverlightApplication1.WCF.DoWorkCompletedEventArgs>(wcfClient_DoWorkCompleted);
                    wcfClient.DoWorkAsync();
                    wcfClient.CloseAsync();

    Web.config:

     <system.serviceModel>
      <behaviors>
       <serviceBehaviors>
        <behavior name="WebApplication1.Service1Behavior">
         <serviceMetadata httpGetEnabled="true"/>
         <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
       </serviceBehaviors>
      </behaviors>
      <bindings>
       <customBinding>
        <binding name="customBinding0">
              <binaryMessageEncoding/>
         <httpTransport/>
        </binding>
       </customBinding>
      </bindings>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
      <services>
       <service behaviorConfiguration="WebApplication1.Service1Behavior" name="WebApplication1.Service1">
        <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="WebApplication1.Service1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       </service>
      </services>
     </system.serviceModel>

     

    2010年10月19日 12:51

答案

  • 错误信息贴一下。我猜是客户端SendTimeout超时了,默认是1分钟哦。 你更改一下客户端的SendTimeout参数试试。


    Mog Liang
    • 已标记为答案 freeplayer 2010年10月25日 2:16
    2010年10月22日 6:26

全部回复