3
votes

After hours of searching for examples, most of which contain only snippets of methods but not the 'whole picture' I am asking for guidance. Starting with the out-of-the-box web.config Visual Studio creates with a new WCF Service, I wrote my basic web service. When you run in debug, WCF Test Client shows the functions that you can test. This is great. Now, wanting to move the code to IIS (first on my local machine, then next to the web server using SSL), I added some code I found on the web. I did have my configuration working at one point but managed to change it so much that I lost the original configurations. So, which that, I have this:

    <system.web>
       <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5"/>
     </system.web>

    <system.serviceModel>
       <protocolMapping>
          <add scheme="http" binding="webHttpBinding"/>
       </protocolMapping>

     <services>
       <service name="TaskTrackerAppService.Service1" behaviorConfiguration="">
       <endpoint address="" 
           binding="webHttpBinding" 
           contract="TaskTrackerAppService.IAppWebService"
           behaviorConfiguration="WebBehavior"></endpoint>

      <endpoint address="mex" binding="mexHttpBinding"
           contract="IMetadataExchange" bindingConfiguration=""></endpoint>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>                
      </serviceBehaviors>

      <endpointBehaviors>
        <behavior name="WebBehavior">
          <webHttp/>
        </behavior>        
      </endpointBehaviors>
    </behaviors>

     <bindings>
      <basicHttpBinding>
        <binding name="TaskTrackerAppService.IAppWebService"></binding>
      </basicHttpBinding>
    </bindings>

    <client>
        <endpoint address="" binding="webHttpBinding" 
          bindingConfiguration="TaskTrackerAppService.IAppWebService" 
          contract="TaskTrackerAppService.IAppWebService"></endpoint>
      </client>


    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
        multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

I configure my client desktop application service reference to point to the local IP http:192.168.0.100:90/AppWebService.svc. Then when I run my client application I get an error:

Could not find default endpoint element that references contract 'ServiceReference.IAppWebService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

So I'd like to get the web.config settings corrected. Then deploy to a hosted IIS service where SSL is ready. As a bonus, is there is way to configure the endpoints such that I can still run debugger and get WCF Test Client. In the once working config WCF test stopped working. Can it support both simple and hosted configurations?

Thanks.

1

1 Answers

2
votes

The <client> section in the <system.serviceModel> is used by client application to specify the "ABC" properties (Address, Binding, and Contract) of the service endpoint. You should have that section in your desktop application so you can simply remove it from your server configurations.

The <client> section in the app.config of your desktop application should, however, have the same "ABC" properties as the service endpoint. Since your service binding is webHttpBinding the client should also have webHttpBinding as binding but I can see that the bindingConfiguration it is referring to, TaskTrackerAppService.IAppWebService is actually a basicHttpBinding so that is a misconfiguration.

Further, since your production environment is using SSL so your production web.config should have binding configuration for SSL something similar to this:

 <bindings>
      <webHttpBinding>
        <binding name="webBindingHTTPS">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>

with the following endpoint configuration:

<endpoint address="" 
           binding="webHttpBinding" 
           contract="TaskTrackerAppService.IAppWebService"
           behaviorConfiguration="webBindingHTTPS"></endpoint>

The best way to achieve this is to use web.config transformation syntax. In that case, your Release web.config could have the following elements:

<bindings>
  <webHttpBinding>
    <binding name="webBindingHTTPS" xdt:Transform="Insert">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>

<endpoint address="" xdt:Transform="Replace" xdt:Locator="Match(name)"
           binding="webHttpBinding" 
           contract="TaskTrackerAppService.IAppWebService"
           behaviorConfiguration="webBindingHTTPS">
</endpoint>

In this way, whenever you project is built in Debug mode it will be configured withoud SSL and whenever is built in Release mode, it will use SSL.