• Advertisement
Sign in to follow this  

[C#] Web Svc Serialize Problem

This topic is 2152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I'm new here so sorry if I mess things up (hello to all of you btw smile.png ). I have a weird problem. I have been making this web service no problem for the past couple of days. I had to use a custom dictionary (code below) to serialize my dictionaries (holding serialized class objects). I made some minor function additions to the web service, went to recompile and BAM visual studio turned all of my SerializableDictionary classes (in function parameters, so for example public void AddMethod(SerialzableDictionary data) would read in the object browser public void AddMethod(DataSet data)) into DataSets sad.png Also I can no longer access the SerializableDictionary class from the client (the object browser just does not show it). I can see the class inside of the web service namespace. I also can load the IL DASM and it shows the class in the web service dll just fine?! So I am confused...I have tried re-creating the web service, restarting my computer/visual studio, to no avail.
Here is the custom dictionary class used to serialize dictionary data across the web service.

[XmlRoot("dictionary")]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IXmlSerializable
{
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
bool wasEmpty = reader.IsEmptyElement;
reader.Read();
if (wasEmpty)
return;
while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
{
reader.ReadStartElement("item");
reader.ReadStartElement("key");
TKey key = (TKey)keySerializer.Deserialize(reader);
reader.ReadEndElement();
reader.ReadStartElement("value");
TValue value = (TValue)valueSerializer.Deserialize(reader);
reader.ReadEndElement();
this.Add(key, value);
reader.ReadEndElement();
reader.MoveToContent();
}
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
foreach (TKey key in this.Keys)
{
writer.WriteStartElement("item");
writer.WriteStartElement("key");
keySerializer.Serialize(writer, key);
writer.WriteEndElement();
writer.WriteStartElement("value");
TValue value = this[key];
valueSerializer.Serialize(writer, value);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
#endregion
}

Here is the picture of the il dasm seeing the class (I have highlighted it).
http://tinypic.com/r/2a8qioh/5 <----------- couldn't embed I tried sorry
Any help is much appreciated! Thanks everyone! smile.png

Share this post


Link to post
Share on other sites
Advertisement
Smells like something wrong with the mex for the service. Can you post that or are you not using WCF for the service?

Share this post


Link to post
Share on other sites
I just created a web service in visual studio (.asmx) then consumed it by adding the web service (generating the soap clients, etc). I was adding classes and functions fine to it unti I added the serialize dictionary. Everything inside the web service dll and see the serialized dictionary just fine while everything outside of it can not. I'm new to creating web services but have used C#/WPF for a while now. Maybe I'm doing something wrong? Thanks for the post so far!


If you look at these 3 examples you'll see it. First image: shows the image of visual studio saying it's a dataset. Second: the code of the actual response class (it's not a data set in the code). The third is the actual code for the web service. I created a temp response at the top of the function to show visual studio showing it as it should (in the web service only sad.png )

Example 1:

http://oi39.tinypic.com/k121d.jpg

Example 2 (the game response code):

[Serializable]
public sealed class GetGamesResponse
{
public GetGamesResponse()
{
}

public GetGamesResponse(SerializableDictionaryEx<int, string> profileGamesList, SerializableDictionaryEx<int, GameSvcDef> gamesSvcList)
{
this.ProfileGamesList = profileGamesList;
this.GameSvcList = gamesSvcList;
}

public bool Status
{
get;
set;
}

public SerializableDictionaryEx<int, string> ProfileGamesList
{
get;
set;
}

public SerializableDictionaryEx<int, GameSvcDef> GameSvcList
{
get;
set;
}
}


Example 3: The actual method in the web service. I created a tmp object to show it showing up as a SerializedDictionary in the service:
http://oi43.tinypic.com/ket3ra.jpg

Share this post


Link to post
Share on other sites
Solution: This is a known big with Microsoft. You have to edit your reference files.
http://support.microsoft.com/kb/815131
Thanks for the reply though, I'll give you a +1 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement