You can call your WCF operation from PowerShell. What you need is to use New-WebServiceProxy cmdlet. New-WebServiceProxy will create a proxy object in order to communicate with the service. Look at the example below:
$uri = "http://192.168.0.1/SampleService.svc?wsdl" $srv = New-WebServiceProxy -Uri $uri -UseDefaultCredential $result = "false" $resultSp = "false" $date = (Get-Date).ToString("yyyy/MM/dd hh:mm:ss") $ srv.NotifyStatus("Type X", 4, "true" ,"Server is running." , [ref] $result, [ref] $resultSp)
- Line 1: declares a variable to hold the wsdl URI
- Line 2: creates a New-WebServiceProxy object based on that URI and with -UseDefaultCredential credential
- Line 8: calls the service operation and passes necessary arguments
Note that your arguments would not be the same as what is presented in the service operation:
For non-string arguments there will be another argument of type Boolean with the same name but with Specified
postfix which determines whether you are providing this argument or not.
That’s why on line 8, I passed “true” after the argument “4”. There is no such an argument in my operation contract.
If your operation has return value you cannot get the returned value in common ways as what we normally do in .NET. You need to pass a reference argument (plus its Specified Boolean reference argument) which will be holding the result.
That’s the reason I have two [ref] arguments at the end. There is no such an argument in the operation contract definition.
To get the list of arguments you can use Get-Member cmdlet or if you are using PowerShell ISE you can use the IntelliSense it provides.