2010-06-16 24 views
7

Todavía soy un novato con wcf y no estoy muy bien informado en .net en general. Tengo un servicio web WCF 4 que utiliza el enfoque de enrutamiento global.asax y web.config muy simplificado utilizando el método de punto final estándar. Este servicio wcf se ejecuta como una aplicación con el sitio web predeterminado en iis 7.5 actualmente. Necesito que sea compatible con las interfaces http y https, si es posible. Si eso es demasiado complejo, solo https. ¿Cómo se maneja mejor manteniendo el enfoque actual?Configuración de WCF 4 con enrutamiento (global.asax) para puntos finales http y https

El contenido de los archivos web.config global.asax.cs y son bastante básicas:

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> 

+0

¿Alguna vez encontró una respuesta? –

Respuesta

9

he encontrado la respuesta: sólo tiene que poner este fragmento en su web.config en la etiqueta ServiceModel:

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

Gracias a este post: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1dd991a1-e32f-4035-a406-994729858b40

Mi web.config completa es la siguiente:

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

No creo que necesite la segunda sección "" en el punto final estándar. No debería causar ningún problema sin embargo. – dan

+0

Muchas gracias, esto resolvió el problema –

3

Los trabajos anteriores, si usted no quiere HTTP y HTTPS. En mi caso, quiero ambos, porque algunos servicios requieren SSL (autenticación) y otros no, ya que la información que proporcionan no es confidencial. La implementación de los servicios de autenticación posee validación y se niega a responder si la solicitud no proviene de un esquema https.

La configuración siguiente funciona si desea configurar HTTP y HTTPS en el mismo punto final.

<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <webHttpBinding> 
     <binding> 
      <security mode="Transport" /> 
     </binding> 
     <binding name="UnsecureBinding"></binding> 
     </webHttpBinding> 
    </bindings> 
    <protocolMapping> 
     <add scheme="http" binding="webHttpBinding" bindingConfiguration="UnsecureBinding" /> 
    </protocolMapping> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" /> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    </system.serviceModel> 
Cuestiones relacionadas