我已经阅读了多个类似的线程,但仍然不知道该怎么做。 我创建了简单的WCF服务,它获取了一些xml数据(在字符串中) 一切都工作正常,直到项目在Windows 7上运行。 现在,当我尝试从客户端向WCF服务发送数据时,我得到了异常
413请求实体太大
我尝试将这两个参数添加到WCF服务上的web.config
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
有人可以查看我的配置并尝试帮助我吗?
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>
(我已经通过web.config文件上的visual studio上下文菜单进行了编辑)
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);
}
我知道我已经粘贴了很多代码,但我不知道如何处理我的web.config文件
正在发送的数据不大,小于1 MB
答案 0 :(得分:0)
您刚刚将此配置放在web.config中吗?
由于您将WCF作为控制台应用程序托管,因此您必须在托管应用程序的App.config中进行配置。