Still learning PS and struggling with objects. I have sample C# code and can not properly implement it in PS.
//Instantiate the web service as an object.
Service1.Service1 obj = new Service1.Service1();
//Instantiate the authentication as an object.
Service1.ValidationSoapHeader authentication = new
Service1.ValidationSoapHeader();
//Assign a DevToken value to the authentication object.
authentication.DevToken = token
obj.ValidationSoapHeaderValue = authentication;
//Build the XML Input String
xmlInput = somexml
{
//Send the XML Input to the MWS
serviceOutput = obj.OrderList(xmlInput);
Here is where I am at with the PS. Obviously this does not work...
$obj = New-WebServiceProxy -Uri $URI -Namespace "WSProxy"-Class "Midnight"
$authentication = New-Object ("WSProxy.ValidationSoapHeader")
$authentication.DevToken = $token
$obj.ValidationSoapHeaderValue = $authentication
# This line works
$obj | Get-Member -MemberType method
$output = $obj.OrderList($inputXML)
Exception calling "OrderList" with "1" argument(s): "System.Web.Services.Protocols.SoapException: Server
request. ---> System.InvalidOperationException: The ConnectionString property has not been initialized.
I’m not sure there’s enough information here for people to help you.
The OrderList method will be specific to the object referenced by $obj which is being returned by whichever service you’re accessing. If it’s a public service or a service that publishes their documentation can you share a link?
How are you setting the $inputXML variable and what is its value?
Thanks for the reply. I thought my problem was just on how the objects were being built, specifically the authentication part. Did I translate the C# example to PS correctly? If so, I am proud! Here is the rest of the code and resources, hope this helps.
I can replicate the error after adding the $authentication object to the ValidationSoapHeaderValue field. I’m using a made up value for the token but I get a different error when it’s not present.
As the object seems to be created properly, I wonder if you just have an authentication problem.
I’m quite happy I at least got that part right! Cool! I am getting help from another person who has provided a different approach but I am getting a different error.
Function GetOrderIDfromOrderNumber() {
[CmdletBinding()]
param (
[Parameter()]
[string]
$OrderNum
)
$devToken = "removed"
$soapUri = "http://ws.vsmidnight.com/Service1.asmx?WSDL"
$midNightWS = New-WebServiceProxy -Uri $soapUri -Namespace WebServiceProxy -Class Service1
$midNightWSAuth = New-WebServiceProxy -Uri $soapUri -Namespace WebServiceProxy -Class ValidationSoapHeader
$midNightWSAuth.DevToken = $devToken
$midNightWS.ValidationSoapHeaderValue = $midNightWSAuth
$xmlInput = "<OrderList>" +
"<InputParameter>" +
"<OrderNumber>" + $OrderNum + "</OrderNumber>" +
"<CustomerCode></CustomerCode>" +
"<CustomerID></CustomerID>" +
"<OrderDateFrom></OrderDateFrom>" +
"<OrderDateTo></OrderDateTo>" +
"<OrderStatus></OrderStatus>" +
"</InputParameter>" +
"</OrderList>"
$midNightWS.OrderList($xmlInput)
}
# Replace "ASDASD" with a valid order number
$soapOutput = GetOrderIDfromOrderNumber("1528")
New-WebServiceProxy : Could not load file or assembly
'file:///C:\Users\jflener\AppData\Local\Temp\megcv3uz.dll' or one of its dependencies. The system
cannot find the file specified.
At C:\Users\jflener\Downloads\soapApi.ps1:10 char:19
+ ... idNightWS = New-WebServiceProxy -Uri $soapUri -Namespace WebServicePr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-WebServiceProxy], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.NewWebServi
ceProxy
New-WebServiceProxy : Could not load file or assembly
'file:///C:\Users\jflener\AppData\Local\Temp\ez3qhm4k.dll' or one of its dependencies. The system
cannot find the file specified.
The class isn’t Service1 it’s Midnight. That should get rid of the error from the first New-WebServiceProxy. I’m not sure why you’d create a second one for auth or what the class would be if you do that.
Have you been able to confirm that your token works?
A couple of other suggestions. Instead of sending a String try an XML object. I don’t think that’s required from the code sample, but it’s worth a try. I’d change your code to use a Here String rather than contatenation.
The other option worth testing would be to build what you’re sending using the examples for PHP or VBA and try sending it with Invoke-WebRequest or Invoke-RestMethod. Here’s an example:
I got a little bit further by changing up a couple lines and got rid of the first error. I’m really not sure what is going on as this is now above my understanding but hopefully this helps. I hope I can get this method working as it looks better but I will try the PHP method too.
I’m not sure there was anything wrong with your first solution. It would appear that everything is being created properly in that solution but there’s a possible problem with the token.
I think I’ve managed to put together the correct code to test with Invoke-WebRequest can you give this a try with your token? It seems to give a more verbose error message (see below).
Thank you, this one works. And I remember now I saw that error before and did not realize it was a credential error. I much to do today now to try and wrap my head around all of this.