简体   繁体   中英

WCF Service doesn't take the right binding

I'm already sorry for asking the same kind of questions over and over. We're running a WCF service with a WPF client application and want to transfer large data from the client application over the WCF service to a database, nothing special about this setting. Now, of course, when trying to upload data (over 16kb) as a byte array I receive the usual 'max array length quota has been exceeded' which brought me to configuring my web.config on the server-side as well as my app.config on the client side to include higher readerquotas for everything.

Now, since this was treated quiet often on stackoverflow, I did a lot of research and finally came to the result of tracking down my service binding via

Trace.WriteLine(OperationContext.Current.EndpointDispatcher.ChannelDispatcher.BindingName)

which gave me http://tempuri.org/:BasicHttpBinding (although other namespaces are configured) and which raise the question whether or not my custom binding is applicated or not. Would you please a have look at the part of code of my web.config (service-side)

<system.serviceModel>


<behaviors>

  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483646" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IDataController" closeTimeout="00:05:00"
      openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00"
      maxBufferPoolSize="500000000" maxBufferSize="500000000" maxReceivedMessageSize="500000000" messageEncoding="Mtom">
      <readerQuotas maxDepth="500000000" maxStringContentLength="500000000"
        maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
    </binding>

    </basicHttpBinding>
</bindings>

<services>
  <service name="DataController">
    <endpoint address="http://vs0092:81/DataController/DataController.svc"  
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IDataController"

              contract="SMS.RC.IDataController" />
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

  </service>
</services>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


</system.serviceModel>

Now the client side app.config looks like this

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IDataController"
               openTimeout="00:05:00"
               sendTimeout="00:05:00"
               receiveTimeout="00:05:00"
               closeTimeout="00:05:00"
               maxBufferPoolSize="500000000"
               maxReceivedMessageSize="500000000"
               maxBufferSize="500000000">
        <readerQuotas maxDepth="500000000"
                      maxStringContentLength="500000000"
                      maxArrayLength="500000000"
                      maxBytesPerRead="500000000"
                      maxNameTableCharCount="500000000" />

      </binding>
     </basicHttpBinding>
     </bindings>
    <client>
        <endpoint address="http://vs0092:81/DataController/DataController.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataController"
            contract="FBCDataController.IDataController" name="BasicHttpBinding_IDataController" />
    </client>
</system.serviceModel>

So do you see the problem? I don't and I've been really put a lot efforts in solving this question but I guess at this point my WCF know how is just to small. Why is the binding of the service not applicated?? Could it be a question of implementing a good ServiceBehavior? Is there a way of looking up the correct name of the service? (which I read has to be the full name with namespace included)

Thanks a lot, Tom

I don't see any obvious problems with your configuration but here are a few pointers:

You may want to review/change your configurations by using the WCF configuration tool - it lists all available settings, not just the ones that are in the config file by default. It's on the Tools menu. I find that if I open it from there first, then immediately close it, I can then right-click on a config in Solution Explorer to run it for that specific file. Not sure why that extra step is needed for me - your mileage may vary.

From within the WCF config tool you can also enable tracing and logging - WCF traces and logs usually have much better information about what goes wrong when something does than the exception message by itself.

Finally, for messages this large you may want to consider using a streaming model instead. Look for a working WCF streaming example and go from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM