C# 如何在url中发送base64字符串?

C# 如何在url中发送base64字符串?,c#,wcf,url,base64,C#,Wcf,Url,Base64,我有一个ionic应用程序,我想通过它向我的WCF服务发送base64字符串。由于base64字符串太大,我收到以下错误-“HTTP错误414。请求URL太长。”我已在IIS上托管此服务。有什么办法可以让它工作吗?我试图在网上搜索这个问题,但没有找到任何方法 这是我的方法- [OperationContract] [WebInvoke(Method = "POST",UriTemplate = "/ReportaBug?base64String={base64String}",

我有一个ionic应用程序,我想通过它向我的WCF服务发送base64字符串。由于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>


这是一个IIS错误,告诉您给定URL的长度超过了限制。IIS的最大URL长度由HttpRuntimeSection.MaxUrlLength属性定义。它的值是260个字符。这可能会导致长度超过配置的
maxurlength
URL出现问题,以下是解决此问题的方法:

更新 我在我的本地主机上测试了你的代码,效果很好。我刚刚在我的
web.config

<httpRuntime targetFramework="4.6.2" maxUrlLength="32768" maxQueryStringLength="32768" />


这是一个IIS错误,告诉您给定URL的长度超过了限制。IIS的最大URL长度由HttpRuntimeSection.MaxUrlLength属性定义。它的值是260个字符。这可能会导致长度超过配置的
maxurlength
URL出现问题,以下是解决此问题的方法:

更新 我在我的本地主机上测试了你的代码,效果很好。我刚刚在我的
web.config

<httpRuntime targetFramework="4.6.2" maxUrlLength="32768" maxQueryStringLength="32768" />




在正文中传输数据,而不是URL。URL有一个最大长度-句点。我们必须解决这个问题。显而易见的是在消息体(它所属的地方)中传输数据。如何在消息体中发送数据?你能展示一些示例代码或引用吗?已经有一段时间了,但是如果我没记错的话,你只需要去掉模板中的参数。不确定是否需要使用流作为方法param的类型并读取它,或者它是否“正常工作”。。。也许您需要使用Bare之外的其他BodyStyle(事实上非常确定)。[OperationContract][WebInvoke(Method=“POST”,UriTemplate=“/ReportaBug,BodyStyle=WebMessageBodyStyle.Wrapped,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json)]void ReportaBug(string base64String);这就是你所说的吗?我想,是的。我已经有一段时间没有在WCF工作了,所以我也必须进行实验。但对我来说,它看起来很好。在正文中传输数据,而不是URL。URL有一个最大长度周期。我们必须处理这个问题。显而易见的是在消息正文(它所属的地方)中传输数据。如何发送消息正文中的数据?请您显示一些示例代码或引用好吗?已经有一段时间了,但如果我没有记错,您只需要删除uriTemplate中的参数。不确定是否需要使用流作为方法参数的类型并读取它,或者它是否“正常工作”" ... 也许您需要使用Bare之外的其他BodyStyle(事实上非常确定)。[OperationContract][WebInvoke(Method=“POST”,UriTemplate=“/ReportaBug,BodyStyle=WebMessageBodyStyle.Wrapped,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json)]void ReportaBug(string base64String);这就是你所说的吗?我想,是的。我已经有一段时间没有在WCF工作了,所以我也必须进行实验。但对我来说,它看起来很好。我更改了maxURLlength,但仍然得到了相同的错误-HTTP错误414。请求URL太长。你的web服务器在哪里?你是通过Internet还是公共网络访问它的?有些问题mes路由器会阻止不寻常的流量。这是在共享网络中。我在IIS上托管了该服务。我用url中的300个字符测试了你的代码,效果很好。是的。300个字符很好。我发送的base64字符串为25824个字符。我更改了maxURLlength,但仍然收到相同的错误-HTTP错误414。请求est URL太长。你的web服务器在哪里?你是通过Internet还是公共网络访问它?有时路由器会阻止不寻常的流量。它在共享网络中。我在IIS上托管了该服务。我用URL中的300个字符测试了你的代码,它工作正常。是的。300个字符工作正常。我发送的base64字符串为25824个字符。