Discussion:
WCF Serialization Problems
(too old to reply)
z***@gmail.com
2007-10-18 15:55:31 UTC
Permalink
I am attempting to serialize a Dictionary<string, string> type in a
WCF data contract. But when i create a service reference to my
contact, the type instead comes out as
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]. How do I fix
this? I am creating the service reference in VS2005 using the WCF
extensions. My WCF host is a simple webservice project. I do not have
any problems creating simple datatypes, or even DataSet in this
manner. Please help.

My contract:

[DataContract]
public class MileageActivity
{
private Dictionary<string, string> mileageActivityPeriods;

[DataMember]
public Dictionary<string, string> MileageActivityPeriods
{
get { return mileageActivityPeriods; }
set { mileageActivityPeriods = value; }
}
}

[MessageContract]
public class MileageActivityPeriodResponse
{
private MileageActivity mileageActivity;

[MessageBodyMember]
public MileageActivity MileageActivity
{
get { return mileageActivity; }
set { mileageActivity = value; }
}
}

Comes out in the Service Reference Proxy as:

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil",
"3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
schemas.datacontract.org/2004/07/Spirit.Contracts.FreeSpirit")]
public partial class MileageActivity
{

private ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
mileageActivityPeriodsField;

/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true,
Order=0)]

[System.Xml.Serialization.XmlArrayItemAttribute("KeyValueOfstringstring",
Namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays",
IsNullable=false)]
public ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
MileageActivityPeriods
{
get
{
return this.mileageActivityPeriodsField;
}
set
{
this.mileageActivityPeriodsField = value;
}
}
}
Nicholas Paldino [.NET/C# MVP]
2007-10-18 16:15:22 UTC
Permalink
Zack,

How did you generate the proxy? If through VS.NET, did you set the
dictionary collection type in the service reference settings dialog? If you
did it through the svcutil utility, then did you use the /collectionType (or
/ct) flag? You need to specify what to use as a collection type in the
proxy.
--
- Nicholas Paldino [.NET/C# MVP]
Post by z***@gmail.com
I am attempting to serialize a Dictionary<string, string> type in a
WCF data contract. But when i create a service reference to my
contact, the type instead comes out as
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]. How do I fix
this? I am creating the service reference in VS2005 using the WCF
extensions. My WCF host is a simple webservice project. I do not have
any problems creating simple datatypes, or even DataSet in this
manner. Please help.
[DataContract]
public class MileageActivity
{
private Dictionary<string, string> mileageActivityPeriods;
[DataMember]
public Dictionary<string, string> MileageActivityPeriods
{
get { return mileageActivityPeriods; }
set { mileageActivityPeriods = value; }
}
}
[MessageContract]
public class MileageActivityPeriodResponse
{
private MileageActivity mileageActivity;
[MessageBodyMember]
public MileageActivity MileageActivity
{
get { return mileageActivity; }
set { mileageActivity = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil",
"3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
schemas.datacontract.org/2004/07/Spirit.Contracts.FreeSpirit")]
public partial class MileageActivity
{
private ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
mileageActivityPeriodsField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true,
Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("KeyValueOfstringstring",
Namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays",
IsNullable=false)]
public ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
MileageActivityPeriods
{
get
{
return this.mileageActivityPeriodsField;
}
set
{
this.mileageActivityPeriodsField = value;
}
}
}
z***@gmail.com
2007-10-18 17:12:11 UTC
Permalink
It was generated in VS.NET (2005) using the "Add Service Reference"
menu. I do not see a service reference settings dialog though. How do
I get there?

thanks!

Zack

On Oct 18, 12:15 pm, "Nicholas Paldino [.NET/C# MVP]"
Post by Nicholas Paldino [.NET/C# MVP]
Zack,
How did you generate the proxy? If through VS.NET, did you set the
dictionary collection type in the service reference settings dialog? If you
did it through the svcutil utility, then did you use the /collectionType (or
/ct) flag? You need to specify what to use as a collection type in the
proxy.
--
- Nicholas Paldino [.NET/C# MVP]
Post by z***@gmail.com
I am attempting to serialize a Dictionary<string, string> type in a
WCF data contract. But when i create a service reference to my
contact, the type instead comes out as
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]. How do I fix
this? I am creating the service reference in VS2005 using the WCF
extensions. My WCF host is a simple webservice project. I do not have
any problems creating simple datatypes, or even DataSet in this
manner. Please help.
[DataContract]
public class MileageActivity
{
private Dictionary<string, string> mileageActivityPeriods;
[DataMember]
public Dictionary<string, string> MileageActivityPeriods
{
get { return mileageActivityPeriods; }
set { mileageActivityPeriods = value; }
}
}
[MessageContract]
public class MileageActivityPeriodResponse
{
private MileageActivity mileageActivity;
[MessageBodyMember]
public MileageActivity MileageActivity
{
get { return mileageActivity; }
set { mileageActivity = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil",
"3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
schemas.datacontract.org/2004/07/Spirit.Contracts.FreeSpirit")]
public partial class MileageActivity
{
private ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
mileageActivityPeriodsField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true,
Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("KeyValueOfstringstring",
Namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays",
IsNullable=false)]
public ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
MileageActivityPeriods
{
get
{
return this.mileageActivityPeriodsField;
}
set
{
this.mileageActivityPeriodsField = value;
}
}
}
Nicholas Paldino [.NET/C# MVP]
2007-10-18 17:25:10 UTC
Permalink
Zack,

I misspoke. The dialog for VS.NET is going to be in the 2008 version.
However, you can still use the /ct (or /collectionType) flag using the
svcutil command line app to generate the proxy, and then add that to your
project. For more details, see:

http://www.request-response.com/blog/PermaLink,guid,ff5fab81-affb-4b2b-aa67-c80bdfc86cbd.aspx
--
- Nicholas Paldino [.NET/C# MVP]
Post by z***@gmail.com
It was generated in VS.NET (2005) using the "Add Service Reference"
menu. I do not see a service reference settings dialog though. How do
I get there?
thanks!
Zack
On Oct 18, 12:15 pm, "Nicholas Paldino [.NET/C# MVP]"
Post by Nicholas Paldino [.NET/C# MVP]
Zack,
How did you generate the proxy? If through VS.NET, did you set the
dictionary collection type in the service reference settings dialog? If you
did it through the svcutil utility, then did you use the /collectionType (or
/ct) flag? You need to specify what to use as a collection type in the
proxy.
--
- Nicholas Paldino [.NET/C# MVP]
Post by z***@gmail.com
I am attempting to serialize a Dictionary<string, string> type in a
WCF data contract. But when i create a service reference to my
contact, the type instead comes out as
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]. How do I fix
this? I am creating the service reference in VS2005 using the WCF
extensions. My WCF host is a simple webservice project. I do not have
any problems creating simple datatypes, or even DataSet in this
manner. Please help.
[DataContract]
public class MileageActivity
{
private Dictionary<string, string> mileageActivityPeriods;
[DataMember]
public Dictionary<string, string> MileageActivityPeriods
{
get { return mileageActivityPeriods; }
set { mileageActivityPeriods = value; }
}
}
[MessageContract]
public class MileageActivityPeriodResponse
{
private MileageActivity mileageActivity;
[MessageBodyMember]
public MileageActivity MileageActivity
{
get { return mileageActivity; }
set { mileageActivity = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil",
"3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
schemas.datacontract.org/2004/07/Spirit.Contracts.FreeSpirit")]
public partial class MileageActivity
{
private ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
mileageActivityPeriodsField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true,
Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("KeyValueOfstringstring",
Namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays",
IsNullable=false)]
public ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
MileageActivityPeriods
{
get
{
return this.mileageActivityPeriodsField;
}
set
{
this.mileageActivityPeriodsField = value;
}
}
}
z***@gmail.com
2007-10-18 18:09:41 UTC
Permalink
Yeah, I actually just found that article while googling. But it doesnt
seem to work for me. I still get the same results.

here is my command:

C:\Program Files\Microsoft Visual Studio 8\VC>svcutil /
ct:System.Collections.Gen
eric.Dictionary`2 http://localhost/Blah.Service.Web/Service.svc

It generates the proxy fine, but I still get
ArrayOfKeyValueOfstringstringKeyValueOfstringstring in there.

Also that article you link appears to state that the Dictionary object
should not have this problem at all, because it already assumes the
client will know its getting a Dictionary object? This is all very
confusing.

Thanks again for your attention to helping me solve this frustrating
problem :)

On Oct 18, 1:25 pm, "Nicholas Paldino [.NET/C# MVP]"
Post by Nicholas Paldino [.NET/C# MVP]
Zack,
I misspoke. The dialog for VS.NET is going to be in the 2008 version.
However, you can still use the /ct (or /collectionType) flag using the
svcutil command line app to generate the proxy, and then add that to your
http://www.request-response.com/blog/PermaLink,guid,ff5fab81-affb-4b2...
--
- Nicholas Paldino [.NET/C# MVP]
Post by z***@gmail.com
It was generated in VS.NET (2005) using the "Add Service Reference"
menu. I do not see a service reference settings dialog though. How do
I get there?
thanks!
Zack
On Oct 18, 12:15 pm, "Nicholas Paldino [.NET/C# MVP]"
Post by Nicholas Paldino [.NET/C# MVP]
Zack,
How did you generate the proxy? If through VS.NET, did you set the
dictionary collection type in the service reference settings dialog? If you
did it through the svcutil utility, then did you use the /collectionType (or
/ct) flag? You need to specify what to use as a collection type in the
proxy.
--
- Nicholas Paldino [.NET/C# MVP]
Post by z***@gmail.com
I am attempting to serialize a Dictionary<string, string> type in a
WCF data contract. But when i create a service reference to my
contact, the type instead comes out as
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]. How do I fix
this? I am creating the service reference in VS2005 using the WCF
extensions. My WCF host is a simple webservice project. I do not have
any problems creating simple datatypes, or even DataSet in this
manner. Please help.
[DataContract]
public class MileageActivity
{
private Dictionary<string, string> mileageActivityPeriods;
[DataMember]
public Dictionary<string, string> MileageActivityPeriods
{
get { return mileageActivityPeriods; }
set { mileageActivityPeriods = value; }
}
}
[MessageContract]
public class MileageActivityPeriodResponse
{
private MileageActivity mileageActivity;
[MessageBodyMember]
public MileageActivity MileageActivity
{
get { return mileageActivity; }
set { mileageActivity = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil",
"3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
schemas.datacontract.org/2004/07/Spirit.Contracts.FreeSpirit")]
public partial class MileageActivity
{
private ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
mileageActivityPeriodsField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true,
Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("KeyValueOfstringstring",
Namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays",
IsNullable=false)]
public ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
MileageActivityPeriods
{
get
{
return this.mileageActivityPeriodsField;
}
set
{
this.mileageActivityPeriodsField = value;
}
}
}
sloan
2007-10-19 04:12:12 UTC
Permalink
Check my more recent blog entry about WCF interface development:

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!158.entry
Post by z***@gmail.com
I am attempting to serialize a Dictionary<string, string> type in a
WCF data contract. But when i create a service reference to my
contact, the type instead comes out as
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]. How do I fix
this? I am creating the service reference in VS2005 using the WCF
extensions. My WCF host is a simple webservice project. I do not have
any problems creating simple datatypes, or even DataSet in this
manner. Please help.
[DataContract]
public class MileageActivity
{
private Dictionary<string, string> mileageActivityPeriods;
[DataMember]
public Dictionary<string, string> MileageActivityPeriods
{
get { return mileageActivityPeriods; }
set { mileageActivityPeriods = value; }
}
}
[MessageContract]
public class MileageActivityPeriodResponse
{
private MileageActivity mileageActivity;
[MessageBodyMember]
public MileageActivity MileageActivity
{
get { return mileageActivity; }
set { mileageActivity = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil",
"3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
schemas.datacontract.org/2004/07/Spirit.Contracts.FreeSpirit")]
public partial class MileageActivity
{
private ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
mileageActivityPeriodsField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute(IsNullable=true,
Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("KeyValueOfstringstring",
Namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays",
IsNullable=false)]
public ArrayOfKeyValueOfstringstringKeyValueOfstringstring[]
MileageActivityPeriods
{
get
{
return this.mileageActivityPeriodsField;
}
set
{
this.mileageActivityPeriodsField = value;
}
}
}
Loading...