none
ArrayOfString vs Generic List

    Question

  • Hello, I read the related threads but didn't see an answer to my question.

    I have an operation defined as such in my service:

    [OperationContract]

    string Transmit(List<string> sData);

    When I added the service reference to my client, I changed the Collection Type to System.Collections.Generic.List.

    But, when I try to use a List<string> as a parameter, I get the following error:

    Cannot convert form 'System.Collections.Generic.List<string>' to 'MyNamesapce.MyService.ArrayOfString'.

    When I look in my client, the operation is defined as such:

    string Transmit(ArrayOfString sData);

    I looked in my proxy classes that were generated and I see the following:

    [System.Diagnostics.DebuggerStepThroughAttribute()]

    [System.CodeDom.Compiler.GenerateCodeAttribute("System.Runtime.Serialization", "4.0.0.0"0]

    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfString", Namespace=http://tempuri.org/, ItemName="string")]

    [System.SerializableAttribute()]

    public class ArrayOfString: System.Collections.Generic.List<string> {

    }

    Why is that happening? And, how do I resolve it so I can use a List<string> instead of ArrayOfString?

    Thank you very much in advance.

    Tuesday, September 03, 2013 5:34 PM

Answers

  • Ok, I suspected the following line was the culprit:

    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfString", Namespace=http://tempuri.org/, ItemName="string")]

    So, I decided to get rid of the http://tempuri.org reference.  I did this as follows:

    1) I created a Constants class, as follows:

    public class Constants

    {

    public const string Namespace=http://localhost:8801/MyNameSpace/Bsp/;

    }

    2) To my WCF interface, I added the following:

    [ServiceContract(Name="IBsp", Namespace=Constants.Namespace, ConfigurationName="IBsp")]

    3) To the class that implemented the interface, I added the following:

    [ServiceBehavior(Name="IBsp", Namespace=Constants.Namespace)]

    4) To my config file, I added a bindingNamespace

    <endpoint address="" binding="netTcpBinding" bindingConfiguration="" bindingNamespace=http://localhost:8801/MyNameSpace/Bsp/ contract="IBsp"/>

    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" bindingNamespace="http://localhost:8801/MyNameSpace/Bsp/ contract="IMetadataExchange" />

    Now when my client grabbed a service reference to the WCF service, I made sure to set the Collection Type of the service to System.Collections.Generic.List and it worked.

    Thanks much!!!

    • Marked as answer by Hiline1961 Tuesday, September 03, 2013 6:02 PM
    Tuesday, September 03, 2013 6:01 PM

All replies

  • Ok, I suspected the following line was the culprit:

    [System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfString", Namespace=http://tempuri.org/, ItemName="string")]

    So, I decided to get rid of the http://tempuri.org reference.  I did this as follows:

    1) I created a Constants class, as follows:

    public class Constants

    {

    public const string Namespace=http://localhost:8801/MyNameSpace/Bsp/;

    }

    2) To my WCF interface, I added the following:

    [ServiceContract(Name="IBsp", Namespace=Constants.Namespace, ConfigurationName="IBsp")]

    3) To the class that implemented the interface, I added the following:

    [ServiceBehavior(Name="IBsp", Namespace=Constants.Namespace)]

    4) To my config file, I added a bindingNamespace

    <endpoint address="" binding="netTcpBinding" bindingConfiguration="" bindingNamespace=http://localhost:8801/MyNameSpace/Bsp/ contract="IBsp"/>

    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" bindingNamespace="http://localhost:8801/MyNameSpace/Bsp/ contract="IMetadataExchange" />

    Now when my client grabbed a service reference to the WCF service, I made sure to set the Collection Type of the service to System.Collections.Generic.List and it worked.

    Thanks much!!!

    • Marked as answer by Hiline1961 Tuesday, September 03, 2013 6:02 PM
    Tuesday, September 03, 2013 6:01 PM
  • Also, I had to remove the [XmlSerializerFormat] from the WCF Interface.

    It used to look like this:

    [ServiceContract(ConfigurationName="IBsp")]

    [XmlSerializerFormat]

    public interface IBsp {

    etc.

    }

    It now looks like this:

    [ServiceContract(Name="IBsp",Namespace=Constants.Namespace, ConfigurationName="IBsp")]

    public interface IBsp {

    etc.

    }

    Thanks!

    Tuesday, September 03, 2013 6:18 PM
  • Hi,

    I am very glad that you have solved your problem by yourself.
    If you have any other problem, welcome to post it in the WCF forums.

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 04, 2013 12:41 AM