Wcf – Calling Service Lbrary from Web Project – What Goes In Web.Config

app-configwcfweb.config

I am new to WCF and am working on a project
where I am building a WCF library that is called
by a Web project (ASP.NET 2.03.5 / C#).

I have a few things going on here.

1) I have provided a compliment contract (IJSON) for my
SOAP contracts (ISOAP) for my JSON web methods.
2) I have one contract, IFileTransferService, that handles
file streaming.

Can you please take a look at my APP.CONFIG and WEB.CONFIG
files and tell me if they look correct or if I am reproducing
that which is in my App.Config in my Web.Config unnecessarily?
If I am using a Service Library, do I really need to be doing
things twice (declaring services, bindings, etc)? Does this look
right?

Also, any other stylistic / constructive comments regarding
what I have in side system.serviceModel is always appreciated.

Thanks for your time.

WEB.CONFIG

<system.serviceModel>
    <client>
      <endpoint name="MySOAPAuthEP" 
                address="http://localhost:1241/WebProj/auth.svc/soap"
                binding="basicHttpBinding" 
                bindingConfiguration="soapWeb" 
                contract="Project.WebAPI.Authentication.ISOAPAuthService" />
      <endpoint name="MySOAPTradeEP"
                address="http://localhost:1241/WebProj/trade.svc/soap"
                binding="basicHttpBinding" 
                bindingConfiguration="soapWeb" 
                contract="Project.WebAPI.Trade.ISOAPTradeService" />
      <endpoint name="MySOAPFileTransferEP"
                address="http://localhost:1241/WebProj/filetransfer.svc/soap"
                binding="basicHttpBinding" 
                bindingConfiguration="httpLargeDataStream"
                contract="Project.WebAPI.FileTransfer.ISOAPFileTransferService" />

      <endpoint name="MyJSONAuthEP"
                binding="webHttpBinding" 
                bindingConfiguration="jsonWeb"
                contract="Project.WebAPI.Authentication.IJSONAuthService"  />
      <endpoint name="MyJSONTradeEP"
                binding="webHttpBinding" 
                bindingConfiguration="jsonWeb"
                contract="Project.WebAPI.Trade.IJSONTradeService"  />
      <endpoint name="MyJSONFileTransferEP"
                binding="webHttpBinding" 
                bindingConfiguration="jsonWeb"
                contract="Project.WebAPI.FileTransfer.IJSONFileTransferService" />
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="soapWeb" />
        <binding name="httpLargeDataStream" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferSize="65536"
          maxReceivedMessageSize="2147483647" messageEncoding="Mtom" transferMode="Streamed">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="jsonWeb" maxBufferSize="1500000" maxBufferPoolSize="1500000"
          maxReceivedMessageSize="1500000">
          <readerQuotas maxDepth="32" maxStringContentLength="656000" maxArrayLength="656000"
            maxBytesPerRead="656000" maxNameTableCharCount="656000" />
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebHttpEPBehavior">
          <webHttp />
        </behavior>
        <behavior name="BasicHttpEPBehavior" />
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
      <service behaviorConfiguration="Default" name="Project.WebAPI.Trade.TradeService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" name="MyJSONTradeEP" contract="Project.WebAPI.Trade.IJSONTradeService" />
        <endpoint address="soap" binding="basicHttpBinding" name="MySOAPTradeEP"
          contract="Project.WebAPI.Trade.ISOAPTradeService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1243/WebProj/trade.svc" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="Default" name="Project.WebAPI.Authentication.AuthService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" name="MyJSONAuthEP" contract="Project.WebAPI.Authentication.IJSONAuthService" />
        <endpoint address="soap" binding="basicHttpBinding" name="MySOAPAuthEP"
          contract="Project.WebAPI.Authentication.ISOAPAuthService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1242/WebProj/auth.svc" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="Default" name="Project.WebAPI.FileTransfer.FileTransferService">

        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
                  binding="webHttpBinding" name="MyJSONFileTransferEP" contract="Project.WebAPI.FileTransfer.IJSONFileTransferService" />

        <endpoint address="soap" 
                  binding="basicHttpBinding" 
                  name="MySOAPFileTransferEP"
                  bindingConfiguration="httpLargeDataStream"
                  contract="Project.WebAPI.FileTransfer.ISOAPFileTransferService" />

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1244/WebProj/filetransfer.svc" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

APP.CONFIG

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="soapWeb" />
        <binding name="httpLargeDataStream"
                 maxReceivedMessageSize="2147483647"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00"
                 transferMode="Streamed"
                 messageEncoding="Mtom"
                 maxBufferSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="jsonWeb" maxBufferSize="1500000" maxBufferPoolSize="1500000"
          maxReceivedMessageSize="1500000">
          <readerQuotas maxDepth="32" maxStringContentLength="656000" maxArrayLength="656000"
            maxBytesPerRead="656000" maxNameTableCharCount="656000" />
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Default" name="Project.WebAPI.Trade.TradeService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" name="MyJSONTradeEP" contract="Project.WebAPI.Trade.IJSONTradeService" />
        <endpoint address="soap" binding="basicHttpBinding" name="MySOAPTradeEP"
          contract="Project.WebAPI.Trade.ISOAPTradeService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1243/WebProj/trade.svc" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="Default" name="Project.WebAPI.Authentication.AuthService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
          binding="webHttpBinding" name="MyJSONAuthEP" contract="Project.WebAPI.Authentication.IJSONAuthService" />
        <endpoint address="soap" binding="basicHttpBinding" name="MySOAPAuthEP"
          contract="Project.WebAPI.Authentication.ISOAPAuthService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1242/WebProj/auth.svc" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="Default" name="Project.WebAPI.FileTransfer.FileTransferService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
                  binding="webHttpBinding" name="MyJSONFileTransferEP" contract="Project.WebAPI.FileTransfer.IJSONFileTransferService" />

        <endpoint address="soap" binding="basicHttpBinding" name="MySOAPFileTransferEP"
                  contract="Project.WebAPI.FileTransfer.ISOAPFileTransferService" />

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1244/WebProj/filetransfer.svc" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebHttpEPBehavior">
          <webHttp />
        </behavior>
        <behavior name="BasicHttpEPBehavior" />
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Best Answer

Several comments to help declutter your config files and make them more readable:

  • you have both the <services> as well as the <client> sections in your web.config and app.config. Why? This is typically not necessary - the server side (where your server code runs) needs the <services>, while the client side that calls the server only needs the <client> section
  • it appears you've used Visual Studio or svcutil.exe to create your configs, as your binding configuration also lists all the binding defaults (that's the huge plethora of settings you have). You could reduce that to leave just those settings you've actually changed for your specific scenario, thus making the configs much smaller and easier to understand
  • do you really need the <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> setting? This basically "fakes" the HttpContext inside your WCF services so that they look and behave much like ASMX webservices - do you need this?
  • this setting here <serviceDebug includeExceptionDetailInFaults="true" /> might be useful and ok in a dev/testing environment, but I would definitely recommend removing it for production
  • are you self-hosting, or hosting in IIS? If you're using IIS to host, the defined <baseAddress> entry will not be used; in a IIS-hosting environment, the base address is ignored, since the location of the *.svc file (the virtual directory it resides in) is your base address and you can't override that

That's about it at first sight :-)

Marc

Related Topic