0

By using Dynamic Proxy namespace, I am trying to create and consume a WCF service dynamically. I have declared a contract like below:

[OperationContract]
long GetStrings(string sinput, int n, out List<String> lstStrings);

on Client side, I am collecting information as below:

        MethodInfo getStrings = proxyType.GetMethod("GetStrings");
        Type strType = getStrings.GetParameters()[0].ParameterType;
        Type strType1 = getStrings.GetParameters()[1].ParameterType;
        Type strType2 = getStrings.GetParameters()[2].ParameterType;

The name of the types are coming as follows:

strType = "String[]&"
strType1 = "String"
strType2 = "int"

My questions are:

  1. Why the order of parameters is getting changed i.e. parameters defined as 'out' are coming before others?
  2. How can correct the order of parameters for the method?
  3. How can I make our parameter to List instead of String[]?

Thanks in advance.

Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44

1 Answers1

0

Usage of out-parameters is not very idiomatic in WCF. You are usually better to wrap your two pieces of returned information (the long and the sequence) in a single response class.

However, if you really need out-parameters for some reason, then I believe that it is supported when the bodystyle is "wrapped" (or maybe "wrappedresponse") but not when it is the default of "bare".

https://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.bodystyle(v=vs.110).aspx

I believe that suggesting that the client code will ever get a List shows a misunderstanding of how WCF and SOAP work. The client-side proxy is made by reading the WSDL generated by the service. WSDL doesn't specify C# types, it specifies XML Schema types. A sequence in XML Schema is being represented by a C# array and that's just how it is. If you need a C# List, you need to wrap the raw proxies in an adapter class of your own design.

PeteAC
  • 789
  • 8
  • 19