Slavvy
Slavvy

Reputation: 561

Unable to expose WCF Endpoint at address

Problem

I have been unable to expose a WCF Service via an end point specified address.

Example my end point address is: http://localhost:36793/services/main

When I host the WCF Service with Visual Studio and try to access the address I get a http 404 Error (Not Found).

What I would expect is to be able to view the WSDL of the address by applying the ?wsdl to the end of the address.

The second strange thing is that I am able to get access to the address by specifying the SVC in the address.

Example: http://localhost:36793/ServiceManager.svc?wsdl

Environment

Thoughts

Something tells me this is either a configuration issue with the web service or something not quite configured in IIS.

Any help would be much appreciated, I have spent a considerable amount of time trying to figure this out. See below for my Web Config.

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
 <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <client />
    <services>
  <service behaviorConfiguration="MexTypeBehaviour" name="Server.ServiceManager">
    <clear />
    <endpoint address="Main" binding="basicHttpBinding" name="Main" contract="Server.IServiceManager" />
    <endpoint address="Mex" binding="mexHttpBinding" name="Mex" contract="Server.IServiceManager" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:36793/services" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
   <serviceBehaviors>
    <behavior name="MexTypeBehaviour" >
        <serviceMetadata httpGetEnabled="true" />
    </behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<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>

</configuration>

Upvotes: 2

Views: 1330

Answers (2)

Yuliam Chandra
Yuliam Chandra

Reputation: 14640

I think you are hosting the service from visual studio that will automatically launch IIS express. When hosting a service in IIS, the base address specified in the config will be ignored.

The .svc file determines the base address of the service - Source

Your configuration is also incorrect when defining mex endpoint.

<endpoint address="Mex" binding="mexHttpBinding" name="Mex" contract="Server.IServiceManager" />

The contract should be IMetadataExchange for mex endpoint.

And each endpoint in the config is not something that can be accessed directly from browser, like

http://localhost:36793/ServiceManager.svc/Main
http://localhost:36793/ServiceManager.svc/Mex

You can consume each endpoint from code, but the address, contract, binding, security and any other aspect must match.

Upvotes: 1

marc_s
marc_s

Reputation: 754438

If the WCF service is hosted by IIS, then the location of the *.svc really determines the service URL - not any settings in <host>/<baseAddresses> or <endpoint>.

Your service base URL is http://yourservername:36793/ServiceManager.svc - and you cannot change that by specifying something else in config.

Since you've defined a Main relative address for your service, you should be able to call your service method at

http://localhost:36793/ServiceManager.svc/Main

The second strange thing is that I am able to get access to the address by specifying the SVC in the address.

It's not strange - it's the IIS hosting behavior that's baked into WCF. It's a feature - not a bug.

If you want to be able to freely define the service URL, you need to use self-hosting providing a console app or Windows service to host your WCF service infrastructure.

Upvotes: 1

Related Questions