2

Am new to scripting. Am stuck with some errors when i try to hit a web service with the input being a xml.

Got the content of the xml and when i try to invoke the WebRequest.

[xml]$sun= Invoke-WebRequest -Uri $uri -CalculateTax post -ContentType "String" -InFile $Input.OuterXml.

where, $uri is the variable which has the url of the service CalculateTax is the Method of the Service $Input is the Variable which has the XML content Getting the error as

Invoke-WebRequest : A parameter cannot be found that matches parameter name 'CalculateTax'.   
+    [xml]$sun= Invoke-WebRequest -Uri $uri -CalculateTax Post -ContentType "string"  ...
+                                        ~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Please help me with this

1 Answer 1

4

Well, there is no -CalculateTax parameter in Invoke-WebRequest cmdlet. And, that is the error you see.

PS C:\> Get-Command Invoke-WebRequest -Syntax

Invoke-WebRequest [-Uri] <uri> [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>]
[-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate
<X509Certificate>] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>]
[-MaximumRedirection <int>] [-Method <WebRequestMethod>] [-Proxy <uri>] [-ProxyCredential <pscredential>]
[-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>]
[-OutFile <string>] [-PassThru] [<CommonParameters>]

Instead of using Invoke-WebRequest, if you are looking at calling a specific method, Look at New-WebServiceProxy. Here is an example from the documentation:

PS C:\>$URI = "http://www.webservicex.net/uszip.asmx?WSDL"
PS C:\>$zip = New-WebServiceProxy -Uri $URI -Namespace WebServiceProxy -Class USZip
PS C:\>$zip | get-member -type method
PS C:\>$zip.getinfobyzip(20500).table
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ravi. I have used New-WebServiceProxy. And it created the proxy for CalculateTax method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.