向 WCF 发送集合时,远程服务器返回错误:NotFound

Posted

技术标签:

【中文标题】向 WCF 发送集合时,远程服务器返回错误:NotFound【英文标题】:The remote server returned an error: NotFound, when sending a Collection to WCF 【发布时间】:2016-11-02 17:39:30 【问题描述】:

我正在尝试向 WCF 发送一个集合。当集合的大小不是很大时(例如大小为10),它正在正常发送。当大小增加到 400-500 的大小时,我有一个错误说:“远程服务器返回错误:未找到”。

有什么建议吗?

此行之后出现错误:

wsClient.importFromExcelAsync(new System.Collections.ObjectModel.ObservableCollection(VIPcollection));

        private void buttonSendFile_Click(object sender, RoutedEventArgs e)
    
        try
        
            if (_fileName == null)
            
                MessageBox.Show("...");
            

            else
            
                var streamFile = UploadTagetsFile(_fileName, _fileStream).ToString();
                var linesSplit = streamFile.ToString().Split('$');
                bool isHeader = (bool)checkBoxIsHeader.IsChecked;
                var splitFile = streamFile.Split('$');
                List<MgarIVR.VipCustomerService.VipCustomer> vipNewCollection = new List<VipCustomerService.VipCustomer>(); ;

                foreach (var vip in splitFile)
                
                    if (isHeader)
                    
                        isHeader = false;
                        continue;
                    
                    var splitTarget = vip.Split(',');
                    try
                    
                        if (IsDigitsOnly(splitTarget[1]) && IsDigitsOnly(splitTarget[2]))
                        

                            var CustomerVip = new MgarIVR.VipCustomerService.VipCustomer();
                            CustomerVip.CustomerName = splitTarget[0];
                            CustomerVip.Phone1 = splitTarget[1];
                            CustomerVip.Phone2 = splitTarget[2];
                            CustomerVip.CustomerID = splitTarget[3];
                            CustomerVip.Skill = splitTarget[4];
                            CustomerVip.Priority = Int16.Parse(splitTarget[5]);
                            vipNewCollection.Add(CustomerVip);


                        


                    
                    catch (Exception ex)
                    
                        LoggerService.LoggerServiceClient wslogClient = new LoggerService.LoggerServiceClient();
                        wslogClient.WriteToLogAsync(ex.Message);
                    


                
                VIPcollection = vipNewCollection;
                VipCustomerService.VipCustomerServiceClient wsClient = new VipCustomerService.VipCustomerServiceClient();                 
                wsClient.importFromExcelAsync(new System.Collections.ObjectModel.ObservableCollection<MgarIVR.VipCustomerService.VipCustomer>(VIPcollection));
                wsClient.importFromExcelCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(wsClient_importFromExcelCompleted);
            


        
        catch (Exception ex)
        
            LoggerService.LoggerServiceClient wslogClient = new LoggerService.LoggerServiceClient();
            wslogClient.WriteToLogAsync(ex.Message);
        
    

ServiceReference.ClientConfig:

<configuration>
<system.serviceModel>
    <bindings>

      <binding>
        <readerQuotas maxArrayLength="2147483647"/>
      </binding>
      <basicHttpBinding>
            <binding name="BasicHttpBinding_ICDNservices" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <!--<binding name="BasicHttpBinding_IVipCustomerService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>-->
          <binding name="BasicHttpBinding_IVipCustomerService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="BasicHttpBinding_IVoiceMessageService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="BasicHttpBinding_ISpecialDaysService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="BasicHttpBinding_IWeekDaysService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="BasicHttpBinding_ILoggerService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="BasicHttpBinding_ISkillService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>


 <client>
  <endpoint address="http://localhost:54245/Services/SpecialDaysService.svc"
   binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISpecialDaysService"
   contract="SpecialDaysService.ISpecialDaysService" name="BasicHttpBinding_ISpecialDaysService" />
  <endpoint address="http://localhost:54245/Services/WeekDaysService.svc"
   binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWeekDaysService"
   contract="WeekDaysService.IWeekDaysService" name="BasicHttpBinding_IWeekDaysService" />
  <endpoint address="http://localhost:54245/Services/LoggerService.svc"
   binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILoggerService"
   contract="LoggerService.ILoggerService" name="BasicHttpBinding_ILoggerService" />
  <endpoint address="http://localhost:54245/Services/CDNservices.svc"
   binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICDNservices"
   contract="CDNservices.ICDNservices" name="BasicHttpBinding_ICDNservices" />
  <endpoint address="http://localhost:54245/Services/VoiceMessageService.svc"
   binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IVoiceMessageService"
   contract="VoiceMessageService.IVoiceMessageService" name="BasicHttpBinding_IVoiceMessageService" />
  <endpoint address="http://localhost:54245/Services/SkillService.svc"
   binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISkillService"
   contract="SkillService.ISkillService" name="BasicHttpBinding_ISkillService" />
  <endpoint address="http://localhost:54245/Services/VipCustomerService.svc"
   binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IVipCustomerService"
   contract="VipCustomerService.IVipCustomerService" name="BasicHttpBinding_IVipCustomerService" />
 </client>
</system.serviceModel>

Web.Config:

<configuration>

<!-- ================= Common(Misc) =================-->
<add key="logo" value="C:\Development\C#\Integration..."/>
<add key="CustomerLogoPath" value="C:\Development\C#\Integration..."/>
<add key="DownloadsFolderVirtualPath" value="ExcelDownload"/>
<add key="DownloadsFolderAbsolutePath" value="C:\Development\C#\Integration..."/>
<add key="NeedCheckAuthorize" value="false"/>
<add key="VoiceMessagePath" value="C:\Development\C#\Integration..."/>

<system.web>
    <compilation debug="true" targetFramework="4.0" />
</system.web>

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

【问题讨论】:

VipCustomerService 的配置是什么样的?如果您要发送文件,您可能会遇到基于 WCF 服务配置设置的文件大小限制。 我编辑了我的帖子,并添加了“ServiceReference.ClientConfig”和“Web.Config”。 【参考方案1】:

你可以使用messageEncoding作为Mtom。

                <binding messageEncoding="Mtom" ></binding> 

你可以增加缓冲区大小

        <binding maxBufferSize="2000000" name="basicHttp"></binding>

您可能还想增加 maxArrayLength

      <binding>
        <readerQuotas maxArrayLength="2147483647"/>
      </binding>

来源:https://social.msdn.microsoft.com/Forums/vstudio/en-US/f5c53569-3969-42ba-af26-40740f306c08/difference-between-maxarraylength-and-maxreceivedmessagesize?forum=wcf

【讨论】:

我在帖子中添加了“ServiceReference.ClientConfig”和“Web.Config” 您好,执行此操作后,出现此错误:“服务参考配置中无法识别元素'messageEncoding'。请注意,Silverlight 中只有一部分 Windows Communication Foundation 配置功能可用。”跨度>

以上是关于向 WCF 发送集合时,远程服务器返回错误:NotFound的主要内容,如果未能解决你的问题,请参考以下文章

WCF:远程服务器返回错误:(413)请求实体太大[重复]

从 jquery 向 wcf webservice 发送数据

具有 30mb 输入字符串的 WCF 服务 - 远程服务器返回错误:(413)请求实体太大

带有 ChannelFactory 的 WCF 客户端,方法返回 ProtocolException / 405 Method not Allowed

(413) 使用 WCF 请求实体太大错误

Post 请求WCF接口报:远程服务器返回错误: (415)