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’ xmlns:oas=‘http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd’ 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