Search code examples
wcf

Running WCF service host inside browser


I have a sample project for a ReST service in WCF. And I am just trying to debug it. When I start the debugging however, the service always starts inside "WCF Test Client" tool. Instead, I am looking for the host to run inside the browser, so that I can download WSDL file.

I have tried removing the "Start options" in the project properties. Then instead of WCF Test Client, service opens in WCF Self Host. If I try to use postman to call the service with WCF Self Host enabled, then execution never reaches the code, and just throws 400 error code.

I also tried attaching the debugger to Chrome, and that did nothing. I have no idea what I am missing in the configuration or Visual studio options. I am expecting that when I start the debugging, it opens a new tab in the browser with the base address of the service.

Below is my current config file.

  <system.web>
<compilation debug="true" />
<membership defaultProvider="ClientAuthenticationMembershipProvider">
  <providers>
    <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
  </providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
  <providers>
    <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
  </providers>
</roleManager>
</system.web>
 <system.serviceModel>
<services>
  <service name="WellacyMobileAPI.Service">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/WellacyMobileAPI/" />
      </baseAddresses>
    </host>
    <endpoint address="" binding="basicHttpBinding" contract="WellacyMobileAPI.IService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="serviceBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceAuthorization serviceAuthorizationManagerType="WellacyMobileAPI.RestAuthorizationManager, WellacyMobileAPI" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
 </system.serviceModel>

Solution

  • The reason why the WCF test client is started by default when debugging the WCF Service is that the browser doesn’t support SOAP message. it means that not all WCF services are http-mode WCF service, so that the browser could not trigger the other WCF service, which communicates with the client via the other binding and message format.
    https://learn.microsoft.com/en-us/dotnet/framework/wcf/wcf-and-aspnet-web-api