Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在自托管WCF服务上设置maxReceivedMessageSize?_C#_Asp.net_.net_Vb.net_Wcf - Fatal编程技术网

C# 如何在自托管WCF服务上设置maxReceivedMessageSize?

C# 如何在自托管WCF服务上设置maxReceivedMessageSize?,c#,asp.net,.net,vb.net,wcf,C#,Asp.net,.net,Vb.net,Wcf,我有一个问题,我给我的自托管WCF服务提供的数据比它能处理的更多。我已经在客户端上设置了maxReceivedMessageSize,但在本例中,客户端正在将数据传递给服务器,因此我需要在服务器上设置maxReceivedMessageSize。我没有使用任何配置文件,我不知道如何在我当前的配置中设置它 客户端: <bindings> <basicHttpBinding> <binding name="BasicHttpBinding

我有一个问题,我给我的自托管WCF服务提供的数据比它能处理的更多。我已经在客户端上设置了maxReceivedMessageSize,但在本例中,客户端正在将数据传递给服务器,因此我需要在服务器上设置maxReceivedMessageSize。我没有使用任何配置文件,我不知道如何在我当前的配置中设置它

客户端:

   <bindings>
      <basicHttpBinding>
       <binding name="BasicHttpBinding_Iplutocomm"
                receiveTimeout="00:05:00" sendTimeout="00:05:00" maxReceivedMessageSize ="210242880">
          <readerQuotas maxStringContentLength="2147483647"  maxArrayLength="2147483647"/>
        </binding>
      </basicHttpBinding>
新更改/更新

Dim myServiceAddress As New Uri("http://" & LocalIpAddress & ":" & tcp_port & "/" & servicename)

myservicehost = New ServiceHost(GetType(plutocomm), myServiceAddress)

'Enable metadata publishing

Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
myservicehost.Description.Behaviors.Add(smb)

myservicehost.Open()
这样做,会覆盖默认的basichhtp绑定吗?我假设框架设置是因为我最初没有专门创建绑定

简而言之,在我的服务上运行的以下代码是否允许我当前的客户端配置“插入”到新绑定?我现在是否仍然只有一个绑定,但我创建了一个,取代了默认绑定

    Dim myServiceAddress As New Uri("http://" & LocalIpAddress & ":" & tcp_port & "/" & servicename)

    myservicehost = New ServiceHost(GetType(plutocomm), myServiceAddress)


    '*******NEW CHANGES

    Dim BasicBinding As New BasicHttpBinding
    BasicBinding.MaxReceivedMessageSize = 2147483647

    myservicehost.AddServiceEndpoint(GetType(plutocomm), BasicBinding, myServiceAddress)

    '/*******NEW CHANGES

    ' Enable metadata publishing.
    Dim smb As New ServiceMetadataBehavior()
    smb.HttpGetEnabled = True
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
    myservicehost.Description.Behaviors.Add(smb)

    myservicehost.Open()
使用,传递您选择的绑定

在您的例子中,这是带有maxReceivedMessageSize集的basicHttpBinding

此方法有5个重载,因此您可以选择所需的重载

类似这样:

Dim myBinding As New BasicHttpBinding() With { _
    Key .MaxReceivedMessageSize = 210242880 _
}
myservicehost.AddServiceEndpoint(GetType(plutocomm), myBinding, myServiceAddress)
更新:


您的绑定需要是“一致的”,它们不需要相同。(如果您的客户端配置有60秒超时,30秒超时的服务器可以工作,但不一致,消息大小也是如此)

出于兴趣,为什么您不能只使用服务配置文件?没有具体原因。这是一个长期存在的应用程序,我按照上面的方法实现,致力于自我托管的示例。我现在不想太多地改变这个概念,因为到目前为止,它是防弹的,并且目前处于生产环境中。可能的重复:是的,这会起作用,但是,在我的opnion中,一个更好的解决方案是使这个配置受驱动。那么你就不必担心将来这种情况是否会改变。