2010-06-16 17 views
7

Wciąż jestem początkującym z wcf i niezbyt dobrze poinformowanym w .net w ogóle. Mam usługę WWW WCF 4, która używa podejścia routingu global.asax i bardzo uproszczonego web.config przy użyciu standardowej metody punktu końcowego. Ta usługa wcf działa jako aplikacja z domyślną witryną internetową w wersji 7.5 obecnie. Potrzebuję go, jeśli to możliwe, obsługiwać zarówno interfejsy http, jak i https. Jeśli to zbyt skomplikowane, to tylko https. Jak najlepiej radzić sobie z utrzymaniem obecnego podejścia?Konfiguracja WCF 4 z routingiem (global.asax) dla punktów końcowych http i https

Zawartość Global.asax.cs i plików web.config są dość podstawowe:

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

Czy kiedykolwiek znalazłeś odpowiedź? –

Odpowiedz

9

Znalazłem odpowiedź: wystarczy umieścić ten fragment w pliku web.config w tagu serviceModel:

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

Dzięki tym poście: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1dd991a1-e32f-4035-a406-994729858b40

Mój pełny plik web.config jest następujący:

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

Nie sądzę, abyś potrzebował drugiej sekcji " w standardowym punkcie końcowym. Nie powinien jednak powodować żadnych problemów. – dan

+0

Wielkie dzięki, to rozwiązało problem –

3

Powyższe działa, jeśli nie chcesz zarówno HTTP, jak i HTTPS. W moim przypadku chcę oba, ponieważ niektóre usługi wymagają protokołu SSL (uwierzytelnianie), a inne nie, ponieważ informacje, które dostarczają, nie są poufne. Implementacja usług uwierzytelniania jest ich własnością i odmawia odpowiedzi, jeśli żądanie nie pochodziło ze schematu https.

Konfiguracja poniżej działa, jeśli chcesz skonfigurować zarówno protokół HTTP, jak i HTTPS w tym samym punkcie końcowym.

<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> 
Powiązane problemy