Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Problem controlling SOAP (de)serialization

Reply
Thread Tools

Problem controlling SOAP (de)serialization

 
 
Martijn Saly
Guest
Posts: n/a
 
      01-11-2006
I have a class that looks like this (simplified):

public class Field {
public string Name;
public string Value;
}

I'm creating a webmethod that has this class as an argument, and the
following SOAP fragment for that is expected:

<Field>
<Name>string</Name>
<Value>string</Value>
</Field>

I want to make this (de)serialized as:

<Field Name="string">string</Field>

This would, of course eat up less bandwidth, and it looks more logical
for a little name/value-class. I've tried adding [XmlAttribute("Name")]
to the Name property, and that works perfectly. So I get this:

<Field Name="string">
<Value>string</Value>
</Field>

Which looks even more silly, I think. So how do I get the aforementioned
way of (de)serialization? Any thoughts/ideas?

--
Thanks,

Martijn Saly
 
Reply With Quote
 
 
 
 
Josh Twist
Guest
Posts: n/a
 
      01-11-2006
You need to decorate your class with the XmlAttributeAttribute:

using System.Xml.Serialization;

public class Field {
[XmlAttribute()]
public string Name;
public string Value;
}

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
 
 
 
Martijn Saly
Guest
Posts: n/a
 
      01-11-2006
Josh Twist wrote:
> You need to decorate your class with the XmlAttributeAttribute:
>
> using System.Xml.Serialization;
>
> public class Field {
> [XmlAttribute()]
> public string Name;
> public string Value;
> }
>
> Josh
> http://www.thejoyofcode.com/
>


Like I said, that'll give me half of what I want:

<Field Name="string">
<Value>string</Value>
</Field>

I can apply XmlAttribute to the Value property as well, but that's not what
I want:

<Field Name="string" Value="string"/>

Because I want this:

<Field Name="string">string</Value>

--
Thanks,

Martijn Saly
 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      01-12-2006
Oops sorry - Martijn, mustn't have finnished reading your post
properly! My apologies:

public class Field {
[XmlAttribute()]
public string Name;

[XmlText()]
public string Value;
}

 
Reply With Quote
 
Martijn Saly
Guest
Posts: n/a
 
      01-12-2006
Josh Twist wrote:
> Oops sorry - Martijn, mustn't have finnished reading your post
> properly! My apologies:
>
> public class Field {
> [XmlAttribute()]
> public string Name;
>
> [XmlText()]
> public string Value;
> }


Thanks
That seems to work perfectly, I didn't know it was that easy

So the response and request of my webservice calls are now properly
(de)serialized, but there's one little thingy left... the HTML pages
that .NET generates for a webservice indicate that the following XML for
my class will/should be in the response/request:

<Field Name="string" />

That might confuse webservice consumers, as this is not correct,
according to the actual output of a webmethod that returns an instance
of my class...

--
Thanks,

Martijn Saly
 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      01-12-2006
I'm not sure there is much you can do about it but your service
consumers shouldn't pay too much attention tot the asmx help page
anyway. It's the WSDL that matters.

You could customise the the DefaultWsdlHelpGenerator page or remove it
altogether (http://www.15seconds.com/issue/040609.htm)?

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
Martijn Saly
Guest
Posts: n/a
 
      01-12-2006
Josh Twist wrote:
> I'm not sure there is much you can do about it but your service
> consumers shouldn't pay too much attention tot the asmx help page
> anyway. It's the WSDL that matters.
>
> You could customise the the DefaultWsdlHelpGenerator page or remove it
> altogether (http://www.15seconds.com/issue/040609.htm)?
>
> Josh
> http://www.thejoyofcode.com/
>


You're right, but if the client doesn't support WSDL (such as an old
version of Visual Objects, for example), the programmer hardcodes the
SOAP message into the source code (arg! but unfortunately it happens)
and he'll probably want to take a look at the help page, rather than
examining the whole WSDL

Anyway, thanks for all the info, I'll take a look at customizing the
DefaultWsdlHelpGenerator.

--
Thanks,

Martijn Saly
 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      01-12-2006
I see your point - but I'd recommend you publish your own documentation
in that case because the help file only goes 'one level deep' anyway.
So if you have any real depth to your classes most of the detail would
be missing.

Good luck!

 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      01-12-2006
I see your point - but I'd recommend you publish your own documentation
in that case because the help file only goes 'one level deep' anyway.
So if you have any real depth to your classes most of the detail would
be missing.

Good luck!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Soap Extension problem (seems that soap request is not sent to server) Frederik Vanderhaegen ASP .Net Web Services 0 10-20-2006 09:18 AM
SOAP over JMS vs SOAP over HTTP Nagesh Java 2 08-12-2006 12:31 AM
Problem of using apache soap to consume WSE 2.0 soap attachment Mullin Yu ASP .Net Web Services 0 10-08-2003 08:09 AM
To SOAP or Not To SOAP? mooseshoes XML 3 09-21-2003 04:38 PM
SOAP Client creation in ASP.NET using MS SOAP Toolkit Sham Ramakrishnan ASP .Net 2 07-01-2003 11:29 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57