1

I have an issue where I am giving my Self Hosted WCF service more data than it can handle. I have set the maxReceivedMessageSize on my client, but in this case the client is passing the data to the server, so I need to set MaxReceivedMessageSize on the server. I am not using any config files, and I am not sure how to get it set within my current config...

Client:

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

Self Hosted Service

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()

New Changes / Update

Doing it like this, will that override the default basichhtp binding that I assume the framework setup because I did not initially specifically create a binding?

I short, will the below code, running on my service, allow my current client config to "plug in" to the new binding? Will I now still have only one binding a sbefore, but my created one, replacing the default one?

    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()
Louis van Tonder
  • 3,664
  • 3
  • 31
  • 62
  • Out of interest, why can't you just use a service config file? – tom redfern Jan 20 '14 at 14:21
  • No specific reason. This is a long standing app that I implemented as per above, working on examples of self hosting. I won't want to change the concept too much now, as its been bulletproof thus far, and currently in a production environment. – Louis van Tonder Jan 20 '14 at 14:26
  • possible duplicate: http://stackoverflow.com/questions/8397532/how-to-override-webservicehostfactory-maxreceivedmessagesize – Lee O. Jan 20 '14 at 14:26

2 Answers2

0

Use ServiceHost.AddServiceEndpoint(), passing in the binding of your choice.

In your case this is the basicHttpBinding with maxReceivedMessageSize set.

This method has 5 overloads so you can just choose the one you want.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • Yes that will work, however, a nicer solution in my opnion would be to make this config driven. Then you don't need to worry about if this changes in the future. – tom redfern Jan 20 '14 at 14:50
0

Something like this:

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

Update:

Your bindings need to be "Coherent", they don't need to be the same.(if your client config have a 60 seconds timeout, a server with 30 seconds timeout would work but would be incoherent, same goes with message Size)

Guish
  • 4,968
  • 1
  • 37
  • 39