2009-06-04 18 views
11

Nel nostro progetto abbiamo un servizio web java che funziona su http e https. Vogliamo utilizzare http internamente e https per la versione esterna della nostra web app.chiamare un servizio web usando WCF su Http e Https

Quindi abbiamo creato la classe proxy nella nostra applicazione e abbiamo impostato il binding per http nel web/app.config e tutto funziona correttamente.

Quali modifiche dovremmo apportare al codice e alla configurazione per supportare https per lo stesso servizio nella nostra applicazione esterna? Se possibile, si prega di fornire frammenti di codice per spiegare!

risposta

0

Vedere Configuring HTTP and HTTPS:

Using Windows Communication Foundation (WCF) over HTTP either requires the use of a host, such as Internet Information Services (IIS), or manual configuration of the HTTP settings through the HTTP Server API. This document describes manually configuring WCF when using HTTP and HTTPS.

E anche vedere WCF Bindings Needed For HTTPS:

I just finished writing my first production WCF application, which worked very well until I deployed it to our production environment. All of a sudden none of the WCF calls would work, and I would get a JavaScript "TestService is not defined" error. When I look inside the JS service reference (in debug mode), I got the following error:

Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]

So apparently my WCF service registered itself as HTTPS (since it is over SSL), but my binding was only configured for HTTP. The solution is to define a custom binding inside your Web.Config file and set the security mode to "Transport". Then you just need to use the bindingConfiguration property inside your endpoint definition to point to your custom binding. The entire HTTPS-enabled system.serviceModel section is below:

0

Capisco che si sta utilizzando WCF per costruire il cliente, che si connette a un servizio Web remoto, tramite HTTPS.

Per fare questo, basta modificare il file di configurazione lato client per l'applicazione WCF-alimentato, sostituendo http://server.address con https://server.address, in configuration/system.serviceModel/client/endpoint/@address. in questo modo:

<configuration> 
    <system.serviceModel> 
    ... 
    <client> 
     <!-- change only the address string --> 
     <endpoint address="https://server.name/Whatever" 
      everything.else.stays.the.same /> 

    </client> 
    </system.serviceModel> 
</configuration> 

(Il percorso del file di configurazione varia in base alle regole normali NET: se si tratta di un app ASPNET, o di un servizio, o ecc)

oppure è possibile impostare la indirizzo esplicitamente nel codice:

// instantiate new proxy to web service 
    var svc= new ServiceClient(); 
    var e = svc.Endpoint; 
    e.Address = new System.ServiceModel.EndpointAddress("https://server.address/JavaServiceUri"); 

Si consiglia vivamente di rendere l'indirizzo configurabile e di non codificarlo. Ciò non significa che debba essere archiviato in app.config, ma dovrebbe essere modificabile. Anche il proxy.

+0

Questo non funziona per la mia situazione, si traduce in un sistema. ArgumentException con messaggio "Lo schema URI fornito 'https' non è valido, previsto 'http'." – RenniePet

2

Suppongo che si stia utilizzando basichttpbinding. Allora avete bisogno di fare due cose:

  • modificare l'indirizzo https :)
  • impostare la modalità di sicurezza per il trasporto di
+0

nice - collegamento alla stessa domanda :) – Rory

+0

@Rory, bella cattura, la risposta è stata lì oltre un anno, tu sei il primo a notare :) –

+0

Ovvio come la tua risposta è, mi ha appena salvato potenzialmente ore. 'Suppongo che tu stia usando basichttpbinding. Il mio SLL stava lavorando per SOAP, ma non funziona per webHttpBinding -REST. Ora che ho identificato il problema, posso iniziare a correggere :) – Doomsknight

22

ho trovato una risposta a scavare intorno MSDN.

Nel mio caso, ho usato una consuetudine vincolante:

<customBinding> 
    <binding name="jsonpBinding"> 
     <jsonpMessageEncoding/> 
     <httpTransport manualAddressing="true"/> 
    </binding> 
</customBinding> 

cui viene fatto riferimento al servizio

<services> 
    <service name="{YourInfoHere}"> 
     <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/> 
    </service> 
</services> 

aggiunta di un secondo legame che ha usato httpsTransport e poi un secondo servizio che ha utilizzato quella vincolante ha fatto il trucco. output finale:

<services> 
     <service name="{YourInfoHere}"> 
      <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/> 
      <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBindingHttps" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/> 
     </service> 
    </services> 
    <bindings> 
     <customBinding> 
      <binding name="jsonpBinding"> 
       <jsonpMessageEncoding/> 
       <httpTransport manualAddressing="true"/> 
      </binding> 
      <binding name="jsonpBindingHttps"> 
       <jsonpMessageEncoding/> 
       <httpsTransport manualAddressing="true" /> 
      </binding> 
     </customBinding> 
    </bindings> 

non può essere l'ideale, ma funziona. Queste erano le uniche modifiche che ho apportato per far funzionare SSL. Poiché è tutto nel trasporto & vincolante, il codice rimane lo stesso.

tutto Link MSDN:

  1. personalizzato Binding: http://msdn.microsoft.com/en-us/library/ms731377.aspx
  2. HttpTransport: http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.aspx
  3. HttpsTransport: http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httpstransportbindingelement.aspx
+3

+1 -Esattamente quello che stavo cercando :) –

Problemi correlati