1

My client is using proxy created from WSDL... Is it possible to setup the service to send List instead of MyCustomObject[]?

I am using

svcutil /t:metadata /ct:System.Collections.Generic.List`1 localhost:8080/managedApp 

but does not work...

My client are in Visual C++

IDE is Visual Studio 2012 --> cannot add service reference

John Saunders
  • 160,644
  • 26
  • 247
  • 397
masuberu
  • 107
  • 3
  • 8
  • You say it "does not work"; how doesn't it work? – carlosfigueira Nov 26 '12 at 01:04
  • 1
    You need to keep in mind that services do not send either lists or arrays. They send XML. List or Array or anything else is something in the client, not the server. – John Saunders Dec 01 '12 at 00:03
  • Hi John, yes you are right clients at the end make a transformation of their datatypes to XML, JSON etc... but why WCF client in C# can send Collections or even custom collections and the server with pick them up? my client is Visual C++ so I was wandering if I could have same behaviour... – masuberu Dec 02 '12 at 00:24

2 Answers2

3

Yes, it is.

/collectionType: if you are using svcutil.exe directly, or if "Add Service Reference" go to Advanced -> Collection Type and change to whatever you want.

Why it's possible is that when using Web Services/WCF "services" your endpoint always receives data serialized in XML/JSON, than this data is deserialized into your C++ data types, and it's up to you in which collection type you want to deserialize received data which contains some collection.

Lev
  • 3,719
  • 6
  • 41
  • 56
  • 1
    Hi Nightwish91, I think "add service reference" from Visual C++ is disabled on Visual Studio 2012, I also tried svcutil as you can see in my post, but still receiving wchar_t ** (which behaves as an array)... Do know what I am missing? – masuberu Nov 25 '12 at 21:00
0

Ok... at the end I gave up, I just sent the data as array instead of std:list...

this is how I did it: 1.- get the metadata from the service using svcutil /t:metadata (NOTE: service has to be running). 2.- create the proxy wsutil *.wsdl *.xsd 3.- add proxy files (.h and .c) to my client and use the proxy functions to the service.

Array are a little bit tricky if you are not familiar with c programming though...

DataContract:

    [DataContract]
        public class CompositeType
        {
            CompositeType2[] ctListValue;
            bool boolValue;
            string stringValue;

            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }

            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }

            [DataMember]
            public CompositeType2[] CtListValue
            {
                get { return ctListValue; }
                set { ctListValue = value; }
            }
        }

        [DataContract]
        public class CompositeType2
        {
            bool boolValue;
            string stringValue;

            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }

            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
        }

and my client side for the calls to array:

// *** COMPOSITETYPE CALL
    CompositeType * co = new CompositeType();
    co->BoolValue = true;
    co->StringValue = L"Im co";

    CompositeType2 co0;
    co0.BoolValue = true;
    co0.StringValue = L"Im co0";

    CompositeType2 co1;
    co1.BoolValue = true;
    co1.StringValue = L"Im co1";

    CompositeType2 co2;
    co2.BoolValue = true;
    co2.StringValue = L"Im co2";

    CompositeType2 ** comType2; // <-- this is my CompositeType2[] I will send to the service
    comType2 = new CompositeType2*[3];

    comType2[0] = &co0;
    comType2[1] = &co1;
    comType2[2] = &co2;

    co->CtListValue = comType2;
    co->CtListValueCount = 3;

    CompositeType* result2;

    BasicHttpBinding_IHelloWorldService_SayHelloCompType(
            proxy, co, &result2,
            heap, NULL, 0, NULL, error);

Hope this helps...

masuberu
  • 107
  • 3
  • 8