New-WebServiceProxy – can’t assign a value to MemberType Property

Welcome Forums General PowerShell Q&A New-WebServiceProxy – can’t assign a value to MemberType Property

Viewing 6 reply threads
  • Author
    Posts
    • #272875
      Participant
      Topics: 1
      Replies: 3
      Points: -14
      Rank: Member

      Hello,

      I try to post a soap to an API on my servers but I’m not able to make it working with the New-WebServiceProxy Cmdlet. I’m not able to assign a username and password to the Security property.

      When I use the Invoke_Webrequest cmdlet I’ve got a correct response.

      Example1 PS1-script:

      $body = “<soap:Envelope xmlns:soap=’http://www.w3.org/2003/05/soap-envelope&#8217; xmlns:oas=’http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&#8217; xmlns:urn=’urn:vpom-ws’>
      <soap:Header>
      <oas:Security>
      <oas:UsernameToken>
      <oas:Username>username</oas:Username>
      <oas:Password>password</oas:Password>
      </oas:UsernameToken>
      </oas:Security>
      </soap:Header>
      <soap:Body>
      <urn:VPOMGetJobInfo>
      <urn:entryIdentifier>2845708</urn:entryIdentifier>
      </urn:VPOMGetJobInfo>
      </soap:Body>
      </soap:Envelope>”

      $Request = Invoke-WebRequest -Credential $Credential -Uri http://10.2.206.11:8081 -Headers (@{SOAPAction=’Read‘}) -Method Post -Body $Body -ContentType application/xml
      $Request.Content

      Result1 = ok

       

      When I try to use New-WebServiceProxy and call the “VPOMGetJobInfo”-method I’ve got an authentication problem.

      Example2 PS1-script:

      $url = “D:\VPOM\_API\vpomwsapi.wsdl”
      $proxy = New-WebServiceProxy -uri $url -UseDefaultCredential -Namespace “VpomApi”
      $proxy.VPOMGetJobInfo(2044814)

      Result2 = not ok

      Exception calling “VPOMGetJobInfo” with “1” argument(s): “VPOMGetJobInfo
      Authentication Required”
      At line:3 char:1
      + $proxy.VPOMGetJobInfo(2044814)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : SoapException

      When I perform a Get-Member on the $proxy I see that I have a property “Security” which I suppose is the property where I should assign the username and password to which I in example1 added in the Header of the request.

      This is the result of the gm.

      $proxy | gm

      Disposed Event System.EventHandler Disposed…
      VPOMGetDeviceInfoCompleted Event VpomApi.VPOMGetDeviceInfoCom…
      VPOMGetJobInfoCompleted Event VpomApi.VPOMGetJobInfoComple…
      VPOMQueueRequestCompleted Event VpomApi.VPOMQueueRequestComp…
      VPOMRegionRequestCompleted Event VpomApi.VPOMRegionRequestCom…
      Abort Method void Abort()
      BeginVPOMGetDeviceInfo Method System.IAsyncResult BeginVPO…
      BeginVPOMGetJobInfo Method System.IAsyncResult BeginVPO…
      BeginVPOMQueueRequest Method System.IAsyncResult BeginVPO…
      BeginVPOMRegionRequest Method System.IAsyncResult BeginVPO…
      CancelAsync Method void CancelAsync(System.Obje…
      CreateObjRef Method System.Runtime.Remoting.ObjR…
      Discover Method void Discover()
      Dispose Method void Dispose(), void IDispos…
      EndVPOMGetDeviceInfo Method VpomApi.DeviceInfoResponse, …
      EndVPOMGetJobInfo Method VpomApi.JobInfoResponse, 5u3…
      EndVPOMQueueRequest Method uint64 EndVPOMQueueRequest(S…
      EndVPOMRegionRequest Method VpomApi.VPOMRegionJobInfo[],…
      Equals Method bool Equals(System.Object obj)
      GetHashCode Method int GetHashCode()
      GetLifetimeService Method System.Object GetLifetimeSer…
      GetType Method type GetType()
      InitializeLifetimeService Method System.Object InitializeLife…
      ToString Method string ToString()
      VPOMGetDeviceInfo Method VpomApi.DeviceInfoResponse, …
      VPOMGetDeviceInfoAsync Method void VPOMGetDeviceInfoAsync(…
      VPOMGetJobInfo Method VpomApi.JobInfoResponse, 5u3…
      VPOMGetJobInfoAsync Method void VPOMGetJobInfoAsync(uin…
      VPOMQueueRequest Method uint64 VPOMQueueRequest(Vpom…
      VPOMQueueRequestAsync Method void VPOMQueueRequestAsync(V…
      VPOMRegionRequest Method VpomApi.VPOMRegionJobInfo[],…
      VPOMRegionRequestAsync Method void VPOMRegionRequestAsync(…
      AllowAutoRedirect Property bool AllowAutoRedirect {get;…
      ClientCertificates Property System.Security.Cryptography…
      ConnectionGroupName Property string ConnectionGroupName {…
      Container Property System.ComponentModel.IConta…
      CookieContainer Property System.Net.CookieContainer C…
      Credentials Property System.Net.ICredentials Cred…
      EnableDecompression Property bool EnableDecompression {ge…
      PreAuthenticate Property bool PreAuthenticate {get;set;}
      Proxy Property System.Net.IWebProxy Proxy {…
      RequestEncoding Property System.Text.Encoding Request…
      Security Property VpomApi.SecurityHeaderType, …
      Site Property System.ComponentModel.ISite …
      SoapVersion Property System.Web.Services.Protocol…
      Timeout Property int Timeout {get;set;}
      UnsafeAuthenticatedConnectionSharing Property bool UnsafeAuthenticatedConn…
      Url Property string Url {get;set;}
      UseDefaultCredentials Property bool UseDefaultCredentials {…
      UserAgent Property string UserAgent {get;set;}

      <wbr /><wbr />

      Could anybody help me out here because I don’t understand how to assign the value to the security header.

      Thank you.

      Kind regards,

      Koen

       

       

       

    • #272884
      Participant
      Topics: 2
      Replies: 377
      Points: 496
      Helping Hand
      Rank: Contributor

      In your Invoke-WebRequest example, you’re specifying a credential ($credential) but in your New-WebServiceProxy example you’re using -UseDefaultCredential which, by default, is the local user.  Does that local user have access to the service?  If not you will to specify an alternate account.

       

    • #272935
      Participant
      Topics: 1
      Replies: 3
      Points: -14
      Rank: Member

      Hi Matt,

      I did some additional testing.

      1. In Invoke-WebRequest the -Credential is not taken in consideration. As you can see there is nowhere in the script I’m assigning a value to it. I did a couple additional tests.
        1. I always removed the -Credential $Credential from the script.
        2. In the header I used as username and password my admin-account, which I use to run Powershell, and I tried the same soap-request with an application-pool user. Both times were succesfull. When I use another normal Active-directory user an error will be generated.
      2. Regarding New-WebServiceProxy I added following lines in the beginning of the script:

      I think this is what you asked me to do. Unfortunately I still get the same error.

      3.

    • #272938
      Participant
      Topics: 1
      Replies: 3
      Points: -14
      Rank: Member

      Hi Matt,

      I did some additional testing.

      1. In Invoke-WebRequest the -Credential is not taken in consideration. As you can see there is nowhere in the script I’m assigning a value to it. I did a couple additional tests.
        1. I always removed the -Credential $Credential from the script.
        2. In the header I used as username and password my admin-account, which I use to run Powershell, and I tried the same soap-request with an application-pool user. Both times were succesfull. When I use another normal Active-directory user an error will be generated.
      2. Regarding New-WebServiceProxy I added following lines in the beginning of the script:

      I think this is what you asked me to do. Unfortunately I still get the same error.

      3.

      It might be interesting to know that as long as I didn’t add security in the header of the soap post with Invoke-WebRequest , that also didn’t work.

      Could it be that the solution could be found in the Security property?

       

       

    • #272965
      Participant
      Topics: 2
      Replies: 377
      Points: 496
      Helping Hand
      Rank: Contributor

      If that is the case, I don’t think you can do this with New-WebServiceProxy because there’s no easy way to send custom headers.

      See: https://powershell.org/forums/topic/how-to-add-ws-security-element-to-soap-request-in-powershell/

    • #272995
      Participant
      Topics: 1
      Replies: 3
      Points: -14
      Rank: Member

      If that is the case, I don’t think you can do this with New-WebServiceProxy because there’s no easy way to send custom headers.

      See: https://powershell.org/forums/topic/how-to-add-ws-security-element-to-soap-request-in-powershell/

      I think we can consider this post resolved then.

      This is the first time I create post here. On many forums posts have a status and you have to change it at the end to “solved” FI. Not here I think or do I overlook anything.

      Thank you very much for your help

    • #273010
      Participant
      Topics: 2
      Replies: 377
      Points: 496
      Helping Hand
      Rank: Contributor

      No problem and don’t worry, you’re not overlooking anything; only moderators can lock the threads.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.