我已经在wcf服务web配置文件中编写了这段代码,我使用这个服务从android应用程序通信我的sql server,我使用httppost方法从android应用程序发送请求,但它显示的查询字符串超出了长度。我们可以通过使用任何其他属性来增加长度,因为我想发送更大的输入,以便有机会发送,否则我必须限制我的查询字符串
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<httpRuntime maxQueryStringLength="2097151" maxUrlLength="2097151"/>
</system.web>
<connectionStrings >
<add name="DBConnection" connectionString="Integrated Security=true;Data Source=LENOVO\SQLEXPRESS;Initial Catalog=Order160415" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<services>
<service name="JsonWcfService.GetEmployees" behaviorConfiguration="EmpServiceBehaviour">
<endpoint address ="" binding="webHttpBinding" contract="JsonWcfService.IGetEmployees" behaviorConfiguration="web">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="EmpServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
答案 0 :(得分:0)
您可以为webHttpBinding
定义绑定配置,并将其分配给端点,就像任何其他绑定一样。为此,请在配置文件中的<system.serviceModel>
部分添加以下内容:
<bindings>
<webHttpBinding>
<binding name="MyWebHttpBinding"
maxBufferPoolSize="2097151"
maxBufferSize="2097151"
maxReceivedMessageSize="2097151">
<readerQuotas maxStringContentLength="2097151" />
</binding>
</webHttpBinding>
</bindings>
我将值设置为您在发布配置中的<httpRuntime>
元素中设置的值。
最后一步是使用bindingConfiguration
元素中的service
属性将此绑定配置分配给您的服务端点:
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="MyWebHttpBinding"
contract="JsonWcfService.IGetEmployees"
behaviorConfiguration="web">
总结一下:
name
属性)分配给bindingConfiguration
元素中的<service>
属性。如果没有绑定配置定义(及其对端点的分配),WCF将使用指定绑定协议的默认值。在这种情况下,maxBufferSize
和maxBufferPoolSize
的默认值为524,288,maxReceivedMessageSize
的默认值为65,536,maxStringContentLength
的默认值为8,192,均小于您设置的2,097,151限制<httpRuntime>
元素。
这些设置特定于WCF服务(或客户端,如果它位于客户端配置中),因此即使IIS接受较大的消息,如果超过绑定定义的限制,WCF也会拒绝它。