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-WebS开发者_运维技巧erviceProxy], 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.exe
utility from the Windows SDK with the /validate
parameter. 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.
You could also try the script version of New-WebServiceProxy, which is based on wsdl.exe
What WCF bindings are you using?
By default a WCF project using the wsHttpBinding, which assumes the client will support more WS-* features than available in the proxy created by powershell's new-webserviceproxy cmdlet.
Change the (or create a new) endpoint binding that uses basicHttpBinding, and ensure that HTTP GET is supported for metadata; e.g.,:
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
精彩评论