2017-10-16 2 views
2

J'ai un service WCF qui fonctionne bien via le navigateur, il renvoie le résultat que je m'attends. Maintenant, lorsque vous essayez d'y accéder via PowerShell, je reçois cette erreurPeut accéder au service WCF via le navigateur, mais pas via un GET dans PowerShell

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. 

Je suis d'hébergement ceci sur IIS comme une application qui pointe à l'emplacement du service sur mon système, appelé « ValidationServiceApp » Je peux y accéder via: "https://myPc/ValidationServiceApp/RemoteService.svc/validationresult/"

Voici le code PowerShell:

[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} #handle unsigned certs as its on my local machine on IIS 
$testurl = "https://myPc/ValidationServiceApp/RemoteService.svc/validationresult/" 
$result = Invoke-WebRequest -Method GET -Uri $testurl 
Write-Host $result 

le service VS:

IRemoteService.cs

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

RemoteService.svc.cs

public bool ValidationResult() 
{ 
    return true; 
    //throw new NotImplementedException(); 
} 

web.config

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

Répondre

1

Envisager d'utiliser l'applet de commande New-WebServiceProxy lorsque vous travaillez avec un webservice WCF dans PowerShell.

$proxy= New-WebServiceProxy -Uri "https://myPc/ValidationServiceApp/RemoteService.svc" 
# retrieve available methods: 
$proxy | Get-Member 
+0

Mais j'utilise REST pas SOAP droit? – thatOneGuy

+0

Bien sûr, vous avez raison. Je voulais dire WCF :) –

+0

en essayant d'accéder à l'URL que vous avez indiqué, à savoir le service pas la méthode dans le service, je reçois: New-WebServiceProxy: La demande a échoué avec le statut HTTP 404: Not Found, et en essayant d'accéder au méthode que j'ai: New-WebServiceProxy: Le document à l'URL https: //mypc/ValidationServiceApp/SASRemoteService.svc/validationresult/ n'a pas été reconnu comme un type de document connu. Des idées ? – thatOneGuy