Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

strange behaviour calling method of wcf from powershell using new-webproxyservice

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...