2017-10-13 5 views
-1

J'ai une application de service WCF mis en place de sorte que lorsque j'appelle l'adresse, il retourne juste vrai.Connexion à l'application de service de repos WCF à partir de PowerShell ne fonctionne pas comme prévu

IRemoteService.cs

 [OperationContract] 
      [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, 
       BodyStyle = WebMessageBodyStyle.Wrapped, 
       UriTemplate = "ValidationResult/")] 
      bool ValidationResult(); 

RemoteService.svc.cs

namespace RemoteService 
{  
    public class RemoteService : IRemoteService 
    { 
     public bool ValidationResult() 
     { 
      return true; 
      //throw new NotImplementedException(); 
     } 
    } 
} 

J'ai ajouté une application sur IIS et maintenant je peux accéder au service à l'adresse suivante:

https://localhost/ValidationServiceApp/RemoteService.svc/validationresult/ 

Renvoie:

{"ValidationResultResult":true} 

Fonctionne très bien. Mais quand je lance le script Powershell suivant, je ne peux pas accéder au service:

$url = "https://localhost/ValidationServiceApp/SASRemoteService.svc/validationresult/" 
$result = Invoke-RestMethod -Method GET -Uri $url 
Write-Host $result 

je dois dire, je l'ai essayé sur une application cliente appelé « Je ne repose » et cela renvoie ce qui est attendu. Donc je pense que ça doit être quelque chose à voir avec powershell. Soit je n'ai pas autorisé quelque chose dans le fichier web.config ou un paramètre manquant dans PowerShell. J'ai également essayé d'ignorer les erreurs de certificat sur powershell. Cela n'a pas aidé.

Erreur de Powershell:

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send. 
At line:18 char:11 
+ $result = Invoke-RestMethod -Method GET -Uri $url 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException 
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand 

Voici le fichier web.config pour le service:

<?xml version="1.0"?> 
<configuration> 

    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.6"/> 
    <httpRuntime targetFramework="4.6"/> 
    <httpModules> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/> 
    </httpModules> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <webHttpBinding>  
     <binding name="webHttpTransportSecurity"> 
      <security mode="Transport"> 
      <transport clientCredentialType="None" proxyCredentialType="None" /> 
      </security> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <services> 
     <service name="RemoteService.RemoteService" behaviorConfiguration="ServiceBehaviour"> 

     <endpoint address ="" 
        binding="webHttpBinding" 
        contract="RemoteService.IRemoteService" 
        bindingConfiguration="webHttpTransportSecurity" 
        behaviorConfiguration="web" /> 

     <endpoint address="mex" 
        binding="mexHttpsBinding" 
        contract="IMetadataExchange" />   

     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 

     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <protocolMapping> 

     <add binding="webHttpBinding" scheme="https"/> 
    </protocolMapping>  
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="ApplicationInsightsWebTracking"/> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" 
     preCondition="managedHandler"/> 
    </modules> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="true"/> 
    <validation validateIntegratedModeConfiguration="false"/> 
    </system.webServer> 

</configuration> 
+0

Êtes-vous en mesure de naviguer 'https: // esukpc70/ValidationServiceApp ....' l'aide du navigateur de la machine client? –

+0

@ChetanRanpariya Je cours tout sur ma propre machine. Je peux accéder à cette URL à partir de mon navigateur et l'application cliente, mais je ne peux pas accéder à partir de powershell – thatOneGuy

+0

Mise à jour de la question pour montrer im travailler avec localhost tout au long – thatOneGuy

Répondre

-1

Managed pour trouver le problème.

J'avais besoin de modifier les permissions sur le service hébergé dans IIS. J'ai donc ajouté les utilisateurs ({pcname}/Users) à la liste des utilisateurs autorisés.

Je supprimerais la question, mais peut-être cela peut aider quelqu'un à l'avenir :)