Problem with collections when consuming generated service

Topics: Service Factory Modeling Edition Forum
Jan 21, 2009 at 9:27 AM
Hi there, I'm having a problem when trying to consume a service which I generated using WSSF.

In my project I have multiple data contracts and collections of those data contracts, but for some reason I have this one collection that is giving me problems when I'm trying to consume the service from the client side. The Collection (called HardwareSettingsInfoCollection in this case) is being generated as a ARRAY, but I specifically changed the collection type to "System.Collections.ObjectModel.Collection`1[T]"

Here follows the code that was generated by Service factory :

using System;
using WcfSerialization = global::System.Runtime.Serialization;
namespace MyProject.DataContracts
{
    /// <summary>
    /// Data Contract Class - HardwareSettingsInfoCollection
    /// </summary>
    [WcfSerialization::CollectionDataContract(Namespace = "urn:MyProject.1.0", ItemName = "HardwareSettingsInfoCollection")]
    public partial class HardwareSettingsInfoCollection : System.Collections.ObjectModel.Collection<HardwareSettingsInfo>
    {
    }
}

Here is where my operation is generated :

[WCF::OperationContract(IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "GetDefaultHardwareSettings", ProtectionLevel = ProtectionLevel.None)]
        MyProject.MessageContracts.GetDefaultHardwareSettingsResponse GetDefaultHardwareSettings(Wems.MessageContracts.GetDefaultHardwareSettingsRequest request);

And here is the message contract :

    [WCF::MessageContract(IsWrapped = false)]
    public partial class GetDefaultHardwareSettingsResponse
    {
        private MyProject.DataContracts.HardwareSettingsInfoCollection defaultHardwareSettingsItem;
             
        [WCF::MessageBodyMember(Name = "DefaultHardwareSettingsItem")]
        public MyProject.DataContracts.HardwareSettingsInfoCollection DefaultHardwareSettingsItem
        {
            get { return defaultHardwareSettingsItem; }
            set { defaultHardwareSettingsItem = value; }
        }
    }

To me, this means that the collection is generated correctly, BUT, when consuming the service using the "add service reference" option in VS 2008 the following code is generated, as you can see, it generates a ARRAY of HardwareSettingsInfo, and not a Collection!?

        public HardwareSettingsInfo[] GetDefaultHardwareSettings(ServiceTester.HardwareSettingsService.TagTypeInfo SettingsTagType) {
            ServiceTester.HardwareSettingsService.GetDefaultHardwareSettingsRequest inValue = new ServiceTester.HardwareSettingsService.GetDefaultHardwareSettingsRequest();
            inValue.SettingsTagType = SettingsTagType;
            ServiceTester.HardwareSettingsService.GetDefaultHardwareSettingsResponse retVal = ((ServiceTester.HardwareSettingsService.HardwareSettingsServiceContract)(this)).GetDefaultHardwareSettings(inValue);
            return retVal.DefaultHardwareSettingsItem;
        }

I tried configuring the service reference to generate all collection to "Collection", but it keeps generating exactly the same code?


Any help or advice will be greatly appreciated
Kind regards

ss
Jan 21, 2009 at 1:40 PM
So.....

Eventually I discovered how to solve this problem......turns out that everything gets generated correctly if the request message's "isWrapped" property is set to true.

I have no idea why it works now......