0

I have a WCF service application. I want to access this service via http request on web browser.

When I run the WCF service on IISExpress, it works but when I published the service on IIS, returns 404 error. How can I fix this issue?

IIS Express screenshot

IIS screenshot

IService.cs

namespace Protek.WebService
{
    [ServiceContract]
    public interface IService
    {
        [WebGet(UriTemplate = "HelloWorld")]
        [OperationContract]
        string HelloWorld();
    }
}

Service.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Protek.WebService.Service" CodeBehind="Service.svc.cs" %>

Service.svc.cs

 namespace Protek.WebService
 {
    public class Service : IService
    {
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
 }

Web.config

  <system.serviceModel>

    <behaviors>

      <serviceBehaviors>
        <behavior name="DefaultBehavior">
          <serviceMetadata httpGetEnabled="true"    />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>

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

    </behaviors>
    <services>

      <service behaviorConfiguration="DefaultBehavior" name="Protek.WebService.Service">
        <endpoint address="ws" binding="wsHttpBinding" contract="Protek.WebService.IService"/>
        <endpoint address="" binding="webHttpBinding" contract="Protek.WebService.IService" behaviorConfiguration="WebBehavior"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:5858/Service" />
          </baseAddresses>
        </host>
      </service>

    </services>

  </system.serviceModel>
Aykut Demirci
  • 168
  • 4
  • 19

2 Answers2

1

First,stackoverflow is technical Ask-reply forum based on English language, please use English in your description and screenshots.
If you want to publish WCF rest service, please refer to the following reply.
How can I use a WCF Service?
Moreover, when we host the WCF service in IIS, the base address is provided by IIS, there is no need to add base address to your configuration file.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d42fc165-052d-476a-9580-1240b3d0293d/specify-endpoint-in-wcf-webconfig?forum=wcf
Feel free to let me know if there is anything I can help with.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22
0

I fixed the issue via I added this line to my service Web.config file. My http error was 404.3

<system.webServer>
    <handlers>
       <add
          name="svc-Integrated"
          path="*.svc"
          verb="*"
          type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
     </handlers>
</system.webServer>
Aykut Demirci
  • 168
  • 4
  • 19
  • Are your tried to Enable Http Activation in windows features? which located in Control-Panel-Program and Features-turn windows features on or off-netframework advanced services-wcf service-http activation. – Abraham Qian Jan 21 '19 at 06:08