How to call a https wcf service

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Matt Bloomfield Matt Bloomfield 5 months, 2 weeks ago.

  • Author
    Posts
  • #59364
    Profile photo of Jaya
    Jaya
    Participant

    I have a https website running say https://localhost:1234/HelloService/ . I have to write a powersheel script which will get connected to this website and consume the data. I could do using http following some tutorials, but i am unable to do it for https.

  • #59437
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    Please share some example code and error messages.

    • #59445
      Profile photo of Jaya
      Jaya
      Participant
      add-type @"
         using System.Net;
         using System.Security.Cryptography.X509Certificates;
         public class TrustAllCertsPolicy : ICertificatePolicy 
          {
            public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate,WebRequest request, int certificateProblem)        
              {
                 return true;
              }
          }
      "@
      
      [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
      $result = Invoke-WebRequest -Uri "https://localhost:1234/HelloService/ "
      
  • #59448
    Profile photo of Jaya
    Jaya
    Participant

    Error :

    Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.
    At D:\Untitled1.ps1:15 char:11
    + $result = Invoke-WebRequest -Uri "https://localhost:1234/HelloService/...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

  • #59529
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    Can you browse to the URL using HTTPS without getting any errors? That's a fairly generic error but I would suspect a problem with either the certificate or the webserver.

    Edit: Just had a thought, won't you always get a certificate error if you go to localhost?

You must be logged in to reply to this topic.