使用 new-webproxyservice 从 powershell 调用 wcf 的奇怪行为方法 [英] strange behaviour calling method of wcf from powershell using new-webproxyservice

查看:40
本文介绍了使用 new-webproxyservice 从 powershell 调用 wcf 的奇怪行为方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我解释一下:

为了测试目的,我构建了一个非常简单的 wcf 服务.
使用 New-WebServiceProxy 从 powershell 消费服务我发现了这种奇怪的行为:

如果在 wcf 服务中我有这种返回 int 的合同:

[操作契约]int GetDictionaryLength();

在 powershell 中调用此方法会出错,并且该方法的定义不是我希望看到的

PS C:\ps>$a |Get-Member getdictionarylength |佛罗里达州 *

<块引用>

类型名称:Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1_022s_pwdservice_svc_wsdl.PWDService

名称:GetDictionaryLength

成员类型:方法

定义:System.VoidGetDictionaryLength(System.Int32&,mscorlib,版本=4.0.0.0,文化=中立,PublicKeyToken=b77a5c561934e089获取字典长度结果,System.Boolean&, mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089GetDictionaryLengthResultSpecified)

像这样改变合同:

[操作契约]字符串 GetDictionaryLength();

在 powershell 中做得很好.

为什么会这样?

WCF 在 .net 4.0 中Powershell 是 V2

解决方案

实验你的答案,然后终于发现这个答案,看来只要在操作合约中加上[XmlSerializerFormat],问题都会迎刃而解,方法签名就会恢复正常.至少我在针对 2.0 .Net 框架和 powershell 进行测试时遇到了问题.

Can someone explain this to me:

I builded an really simple wcf service for testing purposes.
Consuming service from powershell using New-WebServiceProxy I found this stange behaviour:

if in wcf service I have this kind of Contract returning an int:

[OperationContract]
int GetDictionaryLength();

calling this method in powershell gives an error and the definition of the method is not what I would expect to see

PS C:\ps> $a | Get-Member getdictionarylength | fl *

TypeName : Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1_022s_pwdservice_svc_wsdl.PWDService

Name : GetDictionaryLength

MemberType : Method

Definition : System.Void GetDictionaryLength(System.Int32&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 GetDictionaryLengthResult, System.Boolean&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 GetDictionaryLengthResultSpecified)

changing the contract like this:

[OperationContract]
string GetDictionaryLength();

do a great job called in powershell.

Why this?

WCF is in .net 4.0 Powershell is V2

解决方案

Experimenting with your answer, and then finally discover this answer, it seems all your problems will go away if you simply add [XmlSerializerFormat] to the operation contract, and the method signature will return to normal. At least my problems did when testing against a 2.0 .Net framework and powershell.

这篇关于使用 new-webproxyservice 从 powershell 调用 wcf 的奇怪行为方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆