为http和https端点配置带有路由(global.asax)的WCF 4

Jef*_*ier 7 ssl wcf web-services

我仍然是wcf的新手,并且在.net中一般都不太了解.我有一个WCF 4 Web服务,它使用global.asax路由方法,并使用标准端点方法非常简化web.config.此wcf服务作为应用程序运行,目前在iis 7.5上使用默认网站.如果可能的话,我需要它支持http和https接口.如果那太复杂,那么只有https.如何最好地维持当前的方法?

global.asax.cs和web.config文件的内容非常基本:

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes();
    }

    private void RegisterRoutes()
    {
        // Edit the base address of Service1 by replacing the "ippay" string below
        RouteTable.Routes.Add(new ServiceRoute("myservice", new WebServiceHostFactory(),   
typeof(myservice)));     
    }
}


<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
     <standardEndpoint name="" helpEnabled="true"    contentTypeMapper="myservice.Util.RawMapper,myservice">
        </standardEndpoint>
  </webHttpEndpoint>
</standardEndpoints>
Run Code Online (Sandbox Code Playgroud)

Sim*_*ian 9

我找到了答案:您只需将此代码段放在serviceModel标记中的web.config中:

<bindings>
      <webHttpBinding>
        <binding>
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
Run Code Online (Sandbox Code Playgroud)

感谢这篇文章:http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1dd991a1-e32f-4035-a406-994729858b40

我的完整web.config是这样的:

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />   </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>   </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <bindings>
      <webHttpBinding>
        <binding>
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true">
          <security mode="Transport" >

          </security>
        </standardEndpoint>
      </webHttpEndpoint>
    </standardEndpoints>   </system.serviceModel> </configuration>
Run Code Online (Sandbox Code Playgroud)