2017-09-29 103 views
1

我已经阅读了多个类似的线程,但仍然不知道该怎么办。 我创建了简单的WCF服务,它获取一些xml数据(字符串) 一切工作正常,直到项目运行在Windows 7上。 现在,当我尝试从客户端发送数据到WCF服务时,我得到异常WCF配置文件413-请求实体太大

413,请求实体过大的

我已经试过这两个参数添加到我的web.config的WCF服务

maxBufferSize="2147483647"  
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 

可有人p租赁看看我的配置,并试图帮助我?

WCF服务代码:

public class Service1 : IService1 
    { 
     public static Konfiguracja config; 
     public static DBqueries queries; 
     public void WczytajKonfiguracje() 
     { 
      config = new Konfiguracja(); 
      queries = new DBqueries(); 
     } 
     public bool? DodajInfoSprzet(int idKlienta, string haslo, int id_zgloszenia, string HardwareInfoXML, string SoftInfoXML) 
     { 
     ...and some code 
     } 
} 

,这里是我的WCF的web.config文件:

<?xml version="1.0"?> 
<configuration> 

    <connectionStrings> 
    <add name="ProjektSerwisConnectionString" connectionString="Data Source=.\sql12;Initial Catalog=ProjektSerwis;Integrated Security=True" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.6.1" /> 
    <httpRuntime targetFramework="4.6.1"/> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding maxBufferPoolSize="2147483647" 
     maxReceivedMessageSize="2147483647" /> 
     </basicHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping>  
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true"/> 
    </system.webServer> 

</configuration> 

(我用Visual Studio的上下文菜单编辑它的web.config文件)

WCF服务已运行由

namespace SelfService 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Uri baseAddress = new Uri("http://localhost:55555/WcfStart/"); 
      ServiceHost selfHost = new ServiceHost(typeof(Service1), baseAddress); 

      try { 
      selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), "WmiService"); 
      ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 
      smb.HttpGetEnabled = true; 
      selfHost.Description.Behaviors.Add(smb); 
      selfHost.Open(); 
      while(true) 
      { 
       Console.WriteLine("Usługa działa"); 
       Console.WriteLine("Wpisz quit aby zakończyć działanie"); 
       string command = string.Empty; 
       command=Console.ReadLine(); 
       if (String.Equals(command.ToLower(), "quit".ToLower())) 
         break; 
      } 
       // Close the ServiceHostBase to shutdown the service. 
       selfHost.Close(); 
      } 
      catch (CommunicationException ce) 
      { 
       Console.WriteLine("An exception occurred: {0}", ce.Message); 
       selfHost.Abort(); 
      } 
} 
    } 
} 

和客户端具有Web服务只是引用,并通过它连接:

Service1Client scl = new Service1Client(); 
      bool? ok = false; 
      try 
      { 
       ok = scl.DodajInfoSprzet(IdKlienta, haslo, IdZgloszenia, HardwareInfoXML, SoftInfoXml); 
      } 
      catch (Exception ex) 
      { 
       throw new Exception(ex.Message); 
      } 

我konw,我已经粘贴了大量的代码,但我不知道该怎么做我的web.config文件

正在发送的数据不大,小于1 MB

回答

0

你刚刚把这个配置放到web.config中吗?

由于您将WCF托管为控制台应用程序,因此您必须在托管应用程序的App.config中进行配置。