我有一个离子应用程序,我想通过该应用程序将base64字符串发送到WCF服务。由于base64字符串很大,因此出现以下错误-“ HTTP错误414。请求URL太长。”。我已在IIS上托管了此服务。有什么办法可以使它正常工作吗?我尝试在线搜索此问题,但没有任何方法。
这是我的方法-
[OperationContract]
[WebInvoke(Method = "POST",UriTemplate = "/ReportaBug?base64String={base64String}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json )]
void ReportaBug(string base64String);
这是我的web.config文件-
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.2" maxUrlLength="32768" maxQueryStringLength="32768"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0"/>
<services>
<service name="FusionRestService.FusionRestService" behaviorConfiguration="ServiceBehavior">
<endpoint binding="webHttpBinding" contract="FusionRestService.IFusionRestService" behaviorConfiguration="web"></endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="32768"/>
</requestFiltering>
</security>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
答案 0 :(得分:0)
这是一个IIS错误,告诉您给定URL的长度超出限制。 IIS的最大URL长度由HttpRuntimeSection.MaxUrlLength
属性定义。其值是260个字符。这可能会导致问题,问题在于配置的maxUrlLength
URL的长度超过了此长度,这是解决此问题的方法:
https://www.saotn.org/the-length-url-request-exceeds-configured-maxurllength-value/
更新
我在本地主机上测试了您的代码,它的工作正常。我刚刚在我的web.config
<httpRuntime targetFramework="4.6.2" maxUrlLength="32768" maxQueryStringLength="32768" />
和
<security>
<requestFiltering>
<requestLimits maxQueryString="32768"/>
</requestFiltering>
</security>