3

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 Answers 2

4

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
  • Could you give an example, how it can look to add [XmlSerializerFormat] to the operation contract?
    – Nikolas
    Jun 12, 2020 at 8:53
1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.