Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

web services - Configuring WCF 4 with routing (global.asax) for both http & https endpoints

I'm still a newbie with wcf and not too well informed in .net in general. I have a WCF 4 web service that uses the global.asax routing approach and very simplified web.config using the standard endpoint method. This wcf service runs as an application with the default web site on iis 7.5 at present. I need it support both http and https interfaces, if possible. If that's too complex then only https. How is that best handled maintaining the current approach?

The contents of the global.asax.cs and web.config files are pretty basic:

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>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found the answer: you just need to put this snippet in your web.config in the serviceModel tag:

<bindings>
      <webHttpBinding>
        <binding>
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>

Thanks to this post: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1dd991a1-e32f-4035-a406-994729858b40

My full web.config is this:

<?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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...