繁体   English   中英

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

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

我有一个WCF服务应用程序。 我想通过Web浏览器上的http请求访问此服务。

当我在IISExpress上运行WCF服务时,它可以工作,但是当我在IIS上发布该服务时,返回404错误。 如何解决此问题?

IIS Express屏幕截图

IIS屏幕截图

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>

首先,stackoverflow是基于英语的技术性问答论坛,请在描述和屏幕截图中使用英语。
如果要发布WCF休息服务,请参考以下答复。
如何使用WCF服务?
此外,当我们在IIS中托管WCF服务时,基址由IIS提供,因此无需在配置文件中添加基址。
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d42fc165-052d-476a-9580-1240b3d0293d/specify-endpoint-in-wcf-webconfig?forum=wcf
请随时告诉我是否有什么我可以帮助的。

我通过将此行添加到服务Web.config文件中解决了该问题。 我的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