Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 新WebServiceProxy失败_Powershell_Wcf - Fatal编程技术网

Powershell 新WebServiceProxy失败

Powershell 新WebServiceProxy失败,powershell,wcf,Powershell,Wcf,我正在尝试使用PowerShell命令New WebServiceProxy创建到WCF服务的连接 我已经启动并运行了WCF服务(并使用C#代码),但以下PowerShell代码失败: PS C:\>$uri = "http://localhost/Person.svc?wsdl" PS C:\>$client = New-WebServiceProxy -Uri $uri New-WebServiceProxy : Exception has been thrown by the

我正在尝试使用PowerShell命令New WebServiceProxy创建到WCF服务的连接

我已经启动并运行了WCF服务(并使用C#代码),但以下PowerShell代码失败:

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
PS C:\>$uri=”http://localhost/Person.svc?wsdl"
PS C:\>$client=新的WebServiceProxy-Uri$Uri
New WebServiceProxy:调用的目标已引发异常
第1行字符:30

+$client=New WebServiceProxy尝试使用
/validate
参数从执行
svcutil.exe
实用程序。查看实用程序用法,了解
/validate
参数用法的详细信息。请注意,在紧急情况下,您可以使用svcutil.exe创建代理类,然后对其进行编译。回到PowerShell 2.0和新WebProxy的前一天,这是。

您也可以尝试,它基于wsdl.exe

您正在使用什么WCF绑定

默认情况下,使用wsHttpBinding的WCF项目,该项目假定客户端将支持比powershell新的webserviceproxy cmdlet创建的代理中可用的更多的WS-*功能

更改(或创建新的)使用basicHttpBinding的端点绑定,并确保元数据支持HTTP GET;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>


能否打开Visual Studio,添加新的C#项目并将服务引用添加到列出的URL?确保尚未加载实现该服务的解决方案。只是想看看问题是出在PowerShell还是服务上。如果您在浏览器中尝试“”,它是否正常工作?是的,它在C#中正常工作。因此,该问题与PowerShell完全相关。查看通过$Error[0]引发的实际异常将非常有用。exception.InnerException和.StackTrace当我只有指向WCF服务的URL时,如何使用/validate?我使用WSDL生成C#代理类,PowerShell是否有办法编译并将其用作DLL?请参阅
addtype
命令的帮助。您可以编译C#source(到一个动态程序集)并从PowerShell使用它。嗨,运行脚本时,我得到以下错误:警告:C:\Users\frodel\AppData\Local\Temp\bgd3k_a2.0.cs(100,30):警告CS0108:'service1.WcfPersonService.Credentials'隐藏继承的成员'System.Web.Services.Protocols.WebClientProtocol.Credentials'。如果打算隐藏,请使用new关键字。这真的很有趣:您的web服务定义了一个凭据属性,它阻碍了web服务客户端的实现。。。我想这会给任何实施它的人带来痛苦。然而,编译警告应该是可以的,除非它将警告视为错误…我已经启用了它-仍然不是运气。