开发者

Webservice Serialization

I'm currently setting up a generic webservice that takes in credentials, an environment and tries to log a person in. It also returns a collection with return values that matter to for the specific environments.

The problem I'm having is when I want to return part of an object graph in the returnvalues node.

Since return values is a Dictionairy<string, object> it has no clue how to serialize the object graph.

So I thought I'd serialize this into a MemoryStream, load this into an XmlDocument and then serialize this.

How ever that gives the foloowing:

<returnvalues>
 <returnvalue>
  <key>defendant</key> 
  <value xsi:type="xsd:string">
   <?xml version="1.0"?>
    <something xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    </something>
  </value> 
 </returnvalue>
<returnvalues>

What I'd like to get is the following:

<returnvalues>
 <returnvalue>
  <key>defendant</key> 
  <value>
    <something></something>
  &l开发者_高级运维t;/value> 
  </returnvalue>
<returnvalues>

Is this possible? and if so, how do I go about making my response dynamic in such a way? Should I use a different type for my returnvalues node?

I should note this is in .NET 2.0 so i don't have access to any fancy WCF bits :(


You need to do special things when Xml-serializing a generic Dictionary.

This article shows you how to do it.

In your case, you'd need to make the return value of your WebMethod a SerializableDictionary<T1,T2>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜