I’m trying to use the PowerShell command New-WebServiceProxy to create a connection to a WCF Service.
I’ve got the WCF Services up and running (and working from C# code), but the following PowerShell code fails:
PS C:\>$uri = "http://localhost/Person.svc?wsdl"
PS C:\>$client = New-WebServiceProxy -Uri $uri
New-WebServiceProxy : Exception has been thrown by the target of an invocation
At line:1 char:30
+ $client = New-WebServiceProxy <<<< -Uri $uri
+ CategoryInfo : NotSpecified: (:) [New-WebServiceProxy], TargetInvocationException
+ FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.NewWebServiceProxy
What could be the problem here?
Edit; Don’t know if it is relevant, but the Services uses some custom SOAP headers for credentials.
Try executing the
svcutil.exeutility from the Windows SDK with the/validateparameter. Look at the utilities usage for details on the parameter usage for/validate. Note that in a pinch you can just use svcutil.exe to create the proxy class which you would then compile. Back in the day before PowerShell 2.0 and New-WebProxy, this is how we created web service proxies.