1

我创建了一个 WCF 服务,它接收字符串(Text/Json)作为请求,但问题是它只能接收长度为 65536(String.Length)的字符串。我通过谷歌搜索在下面尝试过(绑定 maxReceivedMessageSize="2147483647"),但没有任何变化,它只能接收 65536 的 String.Length 大小,仅此而已。我是 dotNet 和 WCF 词的新手,有人可以帮我向该服务发送大数据(我想向我的 WCF 服务发送大约 10MB 的数据)。

   My Server Config:

   <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <service name="[my-service-name]">
            <endpoint address="http://localhost:8005/MyService"
                  binding="webHttpBinding"
                  contract="[my-service-contract-name]"/>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding maxReceivedMessageSize="2147483647"
            maxBufferSize="2147483647"
            maxBufferPoolSize="2147483647">
              <readerQuotas maxDepth="32"
              maxArrayLength="2147483647"
              maxStringContentLength="2147483647"/>
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <startup> 
          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
      </startup>
    </configuration>


    My Service:

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "MyService")]
        void MyService(String input)
        {
            Console.WriteLine("Request data = " + input.Length);
        }



Client Config:    

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="name-here" maxReceivedMessageSize="2147483647">
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behavior-here">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
4

2 回答 2

1

您的服务的绑定属性设置为 webHttpBinding,并且您将在 basicHttpBinding 下添加诸如 maxReceivedMessageSize 之类的属性。我相信它只是默认为 webHttpbinding 属性。我建议,在您的 httpBinding 下创建一个绑定,并在您的新绑定下进行所有所需的更改 maxReceivedMessageSize 并将其与绑定名称绑定,如下所示:

  <basicHttpBinding>
    <binding name="testMessageBinding" maxReceivedMessageSize="30000000" openTimeout="00:00:02" receiveTimeout="00:00:02" sendTimeout="00:00:02" closeTimeout="00:00:02">
          <readerQuotas maxDepth="32"
          maxArrayLength="2147483647"
          maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>

希望这会有所帮助,如果您还没有查看链接,请阅读以下链接以获取有关自定义绑定、系统提供等方面的更多知识

https://docs.microsoft.com/en-us/dotnet/framework/wcf/system-provided-bindings

于 2018-06-27T12:08:01.633 回答
0
In your config, please add
"<dataContractSerializer maxItemsInObjectGraph="2147483647"/>"

Service Config:
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Client Config:
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
于 2018-06-25T14:56:09.093 回答