2010-06-16 4 views
7

Je suis encore un débutant avec wcf et pas très bien informé dans .net en général. J'ai un service Web WCF 4 qui utilise l'approche de routage global.asax et web.config très simplifié en utilisant la méthode de point de terminaison standard. Ce service wcf fonctionne en tant qu'application avec le site web par défaut sur iis 7.5 actuellement. J'ai besoin de soutenir les interfaces http et https, si possible. Si c'est trop complexe alors seulement https. Comment cela est-il mieux géré en maintenant l'approche actuelle?Configuration de WCF 4 avec routage (global.asax) pour les points de terminaison http et https

Le contenu des Global.asax.cs et les fichiers web.config sont assez simples:

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

Avez-vous déjà trouvé une réponse? –

Répondre

9

J'ai trouvé la réponse: il vous suffit de mettre cet extrait dans votre web.config dans la balise ServiceModel:

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

Merci à ce poste: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1dd991a1-e32f-4035-a406-994729858b40

Mon plein web.config est la suivante:

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

Je ne pense pas que vous ayez besoin de la deuxième section "" dans le point de terminaison standard. Ne devrait pas causer de problèmes cependant. – dan

+0

Merci beaucoup, cela a résolu le problème –

3

Les travaux ci-dessus si vous ne voulez pas HTTP et HTTPS. Dans mon cas, je veux les deux, car certains services nécessitent SSL (authentification) et d'autres non, car les informations qu'ils fournissent ne sont pas sensibles. L'implémentation des services d'authentification possède-t-elle la validation et refuse de répondre si la requête ne provient pas d'un schéma https.

La configuration ci-dessous fonctionne si vous souhaitez configurer HTTP et HTTPS sur le même noeud 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> 
Questions connexes