【问题标题】:Host WCF to existing MVC Web site将 WCF 托管到现有 MVC 网站
【发布时间】:2016-05-16 12:34:10
【问题描述】:

我必须做和已经做的事情:

  1. 将 WCF 服务添加到现有的 mvc Web 应用程序。在某个文件夹下ex:/Service/Service1.svc

  2. 将 MVC 站点托管到 IIS,经过完整运行的站点测试。

    namespace WebApplication3.Service
    {
        public class Service1 : IService1
        {
            public string DoWork()
            {
                return "some string";
            }
        }
    }
    
    
    namespace WebApplication3.Service
    {
        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            [WebInvoke(Method = "GET")]
            string DoWork();
        }
    }
    

和网络配置:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="transportsecurity">
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior">
    <endpoint address="http://localhost/testsite/Service/Service1.svc" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1">
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="mybehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />

当我在 IIS 上浏览服务时,它显示未找到错误 404。

谢谢!

【问题讨论】:

    标签: c# asp.net asp.net-mvc wcf asp.net-mvc-4


    【解决方案1】:

    根据您的托管方式,端点地址很可能不正确/不匹配。

    只需将端点地址更改为空字符串即可。

    <services>
      <service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1">
        </endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    

    此外,您已将其配置为 https(传输安全),因此请确保您使用的是 https url。对于初始测试,我建议首先删除安全性并使用基本绑定。一旦它工作,然后进行安全测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-09
      • 2014-09-02
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多