我有一个WCF服务,它使用带有消息安全性的wsHttpBinding和作为
windows的clientcredentialtype,并且该服务有一个简单的方法
[OperationContract] string SayHello(); public string SayHello() { return "HELLO"; } <wsHttpBinding> <binding name="WSHttpBinding"> <security mode="Message"> <message clientCredentialType="Windows" /> </security> </binding> </wsHttpBinding>
我试图在powershell(版本> = 2)上执行以下操作,我得到以下错误
$wshttpbinding= New-WebServiceProxy -uri http://localhost:52871/Service.svc -Credential DOMAIN\gop PS> $wshttpbinding.SayHello.Invoke() Exception calling "SayHello" with "0" argument(s): "The operation has timed out" At line:1 char:1 + $wshttpbinding.SayHello.Invoke() + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [],MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
但是,当我更改绑定以使用basicHttpBinding时,它工作正常
<basicHttpBinding> <binding name="basicconfig" <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows" /> </security> </binding> </basicHttpBinding> $basichttpbinding= New-WebServiceProxy -uri http://localhost:52871/Service.svc -Credential DOMAIN\gop PS> $basichttpbinding.SayHello.Invoke() HELLO
使用wsHttpBinding时,我的脚本中有什么不同的东西吗?
提前致谢.
最后的方法
我只使用wsHttpBinding来支持WCF事务.但是我很快意识到powershell脚本需要调用的服务方法调用与事务无关.因此,我使用Windows身份验证公开了另一个BasicHttpBinding端点,它使用了以下脚本.请参阅下面的代码段
Try { $cred = new-object -typename System.Management.Automation.PSCredential ` -argumentlist $username,$password -ErrorAction Stop } Catch { LogWrite "Could not create PS Credential" $credErrorMessage = $_.Exception.Message LogWrite $credErrorMessage Break } Try{ $service=New-WebServiceProxy –Uri $url -Credential $cred -ErrorAction Stop } Catch { LogWrite "Could not create WebServiceProxy with $url" $proxyErrorMessage = $_.Exception.Message LogWrite $proxyErrorMessage Break } # Create Request Object $namespace = $service.getType().namespace $req = New-Object ($namespace + ".UpdateJobRequest") LogWrite "Calling service..." $response = $service.UpdateJob($req)
解决方法
我已经在
gallery 中创建了一个PowerShell模块
WcfPS,它可以帮助您使用元数据交换在目标服务的内存代理中创建.我已经使用这个模块访问具有联合安全性的服务,这在配置中非常繁重和困难,因此我相信它也适用于您.还有一个
blog post.所有和所有模块允许您使用soap端点,而无需维护您通常在.net项目中找到的servicemodel配置文件和服务引用.
这是$svcEndpoint保存目标端点值的示例
>探测元数据交换端点
>为代理创建内存类型
>根据导入的配置创建端点
>创建一个频道(代理实例)
$wsImporter=New-WcfWsdlImporter -Endpoint $svcEndpoint -HttpGet $proxyType=$wsImporter | New-WcfProxyType $endpoint=$wsImporter | New-WcfServiceEndpoint -Endpoint $svcEndpoint $channel=New-WcfChannel -Endpoint $endpoint -ProxyType $proxyType
该模块并不完美,所以如果缺少某些东西,请随时做出贡献.
我道歉可能被认为是不完整的答案,但这不符合评论.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。