Strange behavior calling wcf method from powershell using new-webproxyservice

Can someone explain this to me:

I built a really simple wcf service for testing.
PowerShell consumer service using New-WebServiceProxy I found this weird behavior:

If in a wcf service I have a contract that returns an int :

 [OperationContract] int GetDictionaryLength(); 

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

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

Type: 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, PublicKeyToken563419thth )

amend the contract as follows:

 [OperationContract] string GetDictionaryLength(); 

do a great job called powershell.

Why is this?

WCF is in .net 4.0 Powershell - V2

+3
source share
2 answers

Experimenting with your answer, and then finally find out this answer , it seems that all your problems will disappear if you simply add [XmlSerializerFormat] to the operation contract and the method signature returns to normal. At least my problems arose when testing the 2.0.Net environment and powershell.

+4
source

Finally, I 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 created a solution with .net 2.0 (native powershell frameworks) for a client application to use my wfc (.net 4.0) and the definition of the DictionaryLegth () method was:

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

Source: https://habr.com/ru/post/911748/


All Articles