3
votes

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

2

2 Answers

4
votes

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.

1
votes

finally I've discovered this:

PS C:\ps> [int]$int = 0
PS C:\ps> $bool = $true
PS C:\ps> $a.DictionaryLength([ref]$int, [ref]$bool)
PS C:\ps> $int
61

I've build a solution with .net 2.0 (powershell native framework) for a client application to consume my wfc (.net 4.0) and the definition for method DictionaryLegth() was:

void myservice.DictionaryLength(out int DictyionaryLengthResult, out bool DictonaryLengthSpecified)