Search code examples
c#wcfiis-7reverse-proxysvc

WCF service works internally but not externally


I have a WCF service on framework 4 works well inside the internal network. Externally I can see the directory browsing because is enabled in web.config but once I click the svc file is throwing 404 "Server Error in '/' Application". There is also a DMZ reverse proxy and I am sure that is my problem. I checked the IIS-7 logs and the 404 error is not being logged only 200 OK from internal access are logged. The IIS has lots of services and sites running but this is the first time my company is trying WCF with REST service. For days I been looking for answers only finding solutions that are not working on my project. Below is my config file. Thanks in advance for any help.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.net>
<defaultProxy useDefaultCredentials="true"></defaultProxy>
</system.net>

<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel"  switchValue="Warning,ActivityTracing">
 <listeners>
   <add type="System.Diagnostics.DefaultTraceListener" name="Default">
     <filter type="" />
      </add>
      <add name="ServiceModelTraceListener">
        <filter type="" />
      </add>
    </listeners>
  </source>
</sources>
<sharedListeners>
  <add initializeData="X:\RestService\DrillSvc\web_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
    <filter type="" />
  </add>
</sharedListeners>
</system.diagnostics>
<appSettings />
<connectionStrings>
<add name="cn" connectionString="Data Source =test ;  initial catalog=Drillers; User Id=userid; Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>

<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364123" />
  </assemblies>
</compilation>
<authentication mode="Windows" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
    <identity impersonate="false" />
</system.web>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
  <!--<remove name="webDAVModule"/>-->
</modules>

<directoryBrowse enabled="true" />
</system.webServer>
<system.serviceModel>
<bindings>
  <webHttpBinding>
    <binding name="WCFwebBinding">
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="Windows"/>
      </security>
    </binding>  

  </webHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">    </serviceHostingEnvironment>
<services>
  <service behaviorConfiguration="DrillServiceBehavior" name="DrillService">
    <endpoint address="" behaviorConfiguration="WCFDrillWebBehavior" binding="webHttpBinding" contract="IDrillService">
      <identity>
        <dns value="mycompany.com" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="WCFDrillWebBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior name="DrillServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>`

Update: I added a simple HTML page and it works from the external public but the svc file is still throwing 404 error not found.


Solution

  • Finally after doing all kind of changes I found the problem. In the hosted internal server of the wcf service under inetpub/wwwroot there is a config file specifically for the IIS site not the service web.config. After adding this code it worked the first try. The DMZ needed no changes. Hope this will help others.

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