WCF Serialization Problems

  • Thread starter Thread starter zackary.evans
  • Start date Start date
Z

zackary.evans

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;
}
}
}
 
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.
 
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

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]
- (e-mail address removed)


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;
}
}
}
 
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]
- (e-mail address removed)


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

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]
- (e-mail address removed)


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;
}
}
}
 
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 :)

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-4b2...

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


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?
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]
- (e-mail address removed)

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;
}
}
}
 
Back
Top