简体   繁体   English

如何在IIS托管的WCF服务中使用HTTP请求访问任何方法?

[英]How to access any method using http request in wcf serice which is hosted on IIS?

I have a WCF service application. 我有一个WCF服务应用程序。 I want to access this service via http request on web browser. 我想通过Web浏览器上的http请求访问此服务。

When I run the WCF service on IISExpress, it works but when I published the service on IIS, returns 404 error. 当我在IISExpress上运行WCF服务时,它可以工作,但是当我在IIS上发布该服务时,返回404错误。 How can I fix this issue? 如何解决此问题?

IIS Express屏幕截图

IIS屏幕截图

IService.cs IService.cs

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

Service.svc Service.svc

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

Service.svc.cs Service.svc.cs

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

Web.config 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>

First,stackoverflow is technical Ask-reply forum based on English language, please use English in your description and screenshots. 首先,stackoverflow是基于英语的技术性问答论坛,请在描述和屏幕截图中使用英语。
If you want to publish WCF rest service, please refer to the following reply. 如果要发布WCF休息服务,请参考以下答复。
How can I use a WCF Service? 如何使用WCF服务?
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. 此外,当我们在IIS中托管WCF服务时,基址由IIS提供,因此无需在配置文件中添加基址。
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d42fc165-052d-476a-9580-1240b3d0293d/specify-endpoint-in-wcf-webconfig?forum=wcf 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. 请随时告诉我是否有什么我可以帮助的。

I fixed the issue via I added this line to my service Web.config file. 我通过将此行添加到服务Web.config文件中解决了该问题。 My http error was 404.3 我的http错误是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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM