2009-06-04 10 views
11

Dans notre projet, nous avons un service Web Java qui fonctionne sur http et https. Nous souhaitons utiliser http en interne et https pour la version externe de notre application Web.appel d'un service Web en utilisant WCF sur Http et Https

Nous avons donc créé la classe proxy dans notre application et nous avons configuré la liaison pour http dans le fichier web/app.config et tout fonctionne correctement.

Quels changements devrions-nous apporter au code et à la configuration pour prendre en charge https pour le même service dans notre application externe? Si possible s'il vous plaît fournir des extraits de code pour expliquer!

Répondre

0

S'il vous plaît voir 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.

Et aussi voir 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

Je comprends que vous utilisez WCF pour construire le client, qui se connecte à un service Web à distance, via le protocole HTTPS. Pour cela, il suffit de modifier le fichier de configuration côté client pour l'application alimentée par WCF, en remplaçant http://server.address par https://server.address, dans configuration/system.serviceModel/client/endpoint/@address. comme ceci:

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

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

(Le chemin vers le fichier de configuration varie selon les règles .NET régulièrement: que ce soit une application ASPNET ou un service, ou etc.)

OU vous pouvez définir la adresse explicitement dans le code:

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

Je vous conseille fortement de rendre l'adresse configurable, et non de le coder en dur. Cela ne signifie pas qu'il doit être stocké dans app.config, mais il doit être modifiable. Le proxy, aussi.

+0

Cela ne fonctionne pas pour ma situation, il en résulte un système. ArgumentException avec message "Le schéma URI fourni" https "est invalide, attendu" http "." – RenniePet

2

Je suppose que vous utilisez basichttpbinding. Ensuite, vous devez faire deux choses:

  • changer l'adresse https :)
  • définir le mode de sécurité pour le transport
+0

agréable - reliant à la même question :) – Rory

+0

@Rory, belle prise, la réponse a été là plus d'un an, vous êtes les premiers à remarquer :) –

+0

Aussi évident que votre réponse est, il me sauvé potentiellement heures. 'Je suppose que vous utilisez basichttpbinding.' Mon SLL travaillait pour SOAP, mais il ne marche pas travailler pour webHttpBinding -Reste. Maintenant que j'identifié le problème, je peux commencer à corriger :) – Doomsknight

22

J'ai trouvé une réponse à creuser autour de MSDN.

Dans mon cas, j'utilisais une reliure personnalisée:

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

qui a été référencé dans le service

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

Ajout d'une seconde liaison qui a utilisé httpsTransport puis un second service qui a utilisé cette la liaison a fait l'affaire. Sortie 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> 

Peut-être pas idéal, mais cela fonctionne. Ce sont les seuls changements que j'ai faits pour que SSL fonctionne. Puisque tout est dans le transport & de liaison, le code reste le même.

Liens pertinents MSDN:

  1. sur mesure Reliure: 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 -Exactement ce que je cherchais :) –