views:

276

answers:

2

I have build an APi which is a WCF Service. In the web.config for the service i have specified a custom bindong looking like this:

<bindings>
  <wsHttpBinding>
    <binding name="FxBinding"
      maxBufferPoolSize="2147483647"
      maxReceivedMessageSize="2147483647"
      closeTimeout="00:20:00"
      openTimeout="00:20:00"
      receiveTimeout="00:20:00"
      sendTimeout="00:20:00"
      messageEncoding="Mtom">
              <readerQuotas
      maxDepth="64"
      maxStringContentLength="2147483647"
      maxArrayLength="2147483647"
      maxBytesPerRead="4096"
      maxNameTableCharCount="16384" />
      <security mode="None"></security>
    </binding>
  </wsHttpBinding>
</bindings>

Telling the configuration to use the binding i have specified by setting the "name" attribute in the endpoint tag:

<services>
  <service name="Dba.Admanager.Api.ListingServiceContract" behaviorConfiguration="Dba.Admanager.Api.ListingServiceContractBehavior">
    <endpoint address="" binding="wsHttpBinding" name="FxBinding" contract="Dba.Admanager.ApplicationController.Api.IListingServiceContract">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>

See. When i create an web reference to the service in VS2008 a app.config are generated. In this app.config the binding used, should be the one specified above. But in the app.config is a default binding with default values in the "maxArrayLength" for instance.

<bindings>
        <wsHttpBinding>
            <binding name="FxBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="">
                        <extendedProtectionPolicy policyEnforcement="Never" />
                    </transport>
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://l-aar-00424012.corp.ebay.com/Admanager.Api/ListingServiceContract.svc"
            binding="wsHttpBinding" bindingConfiguration="FxBinding" contract="WCFListingServiceContract.IListingServiceContract"
            name="FxBinding">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>

I can see that the client is using the FxBinding configuration, but why on earth all the values are default, i dont understand. Can anubody give at at clue on how to customize the binding-values and make it reflect on the "client"-part?

If i change the values manualle in the app.config i get the desired effect, but every time the webreference is updated, VS just adds a new binding with the default values.

+2  A: 

Information such as maxArrayLength is not part of the WSDL, so the client cannot infer it and just takes default values.

Darin Dimitrov
A: 

As Darin already mentioned - since those binding parameters aren't part of the interoperable metadata between service and client, they can't be automagically picked up by the client when you create a new client proxy.

What you could do is this:

  • define your binding configurations in a separate config file and reference that on the server - i.e. put everything inside <bindings> into bindings.config and then reference it from your server side web.config or app.config:

    <system.serviceModel>
        <bindings configSource="bindings.config" />
    </system.serviceModel>
    
  • Then copy that bindings.config to your client side and do the same thing there in your app.config.

Note: yes, Visual Studio will complain about the "configSource" not being defined and all - but that's just a flaw in the VS intellisense for config files. Trust me - it works - I use it everyday in production systems! Every configuration section in .NET has a "configSource" attribute!

With this method, you create one file that contains those binding configurations for your system and you can use it on both the server and the client side.

marc_s
Thancs marc_s. This is good value information and makes the config evne more readable. Plus: It saves med the trouble of keeping both the configuatons in sync.
esbenr