XML Web Services

T

Tony C

I have played with XML Web Services for a while now and can get them
working with simple parameters such as integers and strings but now I
want to do something more complicated and I have become stuck. The
SOAP request below is going to be posted to my Web Service. The format
of the XML is such that there will be many <Command> elements for all
the different pieces and there moves.

Example SOAP Request
====================
<soap:Envelope>
<soap:Body>
<Player xmlns="http://tempuri.org/chess">
<Information>
<PlayerID>D345B</PlayerID>
<PlayerName>Barney Smith</PlayerName>
</Information>
<Commands>
<Command CurPos="B6" NewPos="D6" Colour"White">ROOK</Command>
<Command CurPos="D1" NewPos="A4" Colour"White">QUEEN</Command>
<Command CurPos="F1" NewPos="E4"
Colour"White">KNIGHT</Command>
</Commands>
</Player>
</soap:Body>
</soap:Envelope>

My intention is to parse the XML coming into the Web Service and place
each of the players moves into a table in a SQL Server database.

Question: "What would the signature of the Web Service need to be to
accept this reponse?"

I have done some looking and I have seen references to a Type called
XMLNodeKey or something, that can hold an XML document minus all the
declaritive stuff. This would give me a signature of:

AcceptMove(ByVal XMLPlayerMove as XMLNodeKey) as Integer

if this is correct then fine. but I cant see how I can then treat this
as an XMLDocument and pick out all the relevant stuff.

Maybe somebody out there as done this before, and could help. The
database stuff i can handle its just the signature of the Web Service
and some example code of how to extract the data from the XML that I
need.

I would really appreciate if anyone out there could help me, as i
think Im gonna go mad.

Cheers
 
T

Tomas Restrepo \(MVP\)

Hi Tony,
I have played with XML Web Services for a while now and can get them
working with simple parameters such as integers and strings but now I
want to do something more complicated and I have become stuck. The
SOAP request below is going to be posted to my Web Service. The format
of the XML is such that there will be many <Command> elements for all
the different pieces and there moves.

Example SOAP Request
====================
<soap:Envelope>
<soap:Body>
<Player xmlns="http://tempuri.org/chess">
<Information>
<PlayerID>D345B</PlayerID>
<PlayerName>Barney Smith</PlayerName>
</Information>
<Commands>
<Command CurPos="B6" NewPos="D6" Colour"White">ROOK</Command>
<Command CurPos="D1" NewPos="A4" Colour"White">QUEEN</Command>
<Command CurPos="F1" NewPos="E4"
Colour"White">KNIGHT</Command>
</Commands>
</Player>
</soap:Body>
</soap:Envelope>

My intention is to parse the XML coming into the Web Service and place
each of the players moves into a table in a SQL Server database.

Question: "What would the signature of the Web Service need to be to
accept this reponse?"

I have done some looking and I have seen references to a Type called
XMLNodeKey or something, that can hold an XML document minus all the
declaritive stuff. This would give me a signature of:

AcceptMove(ByVal XMLPlayerMove as XMLNodeKey) as Integer

if this is correct then fine. but I cant see how I can then treat this
as an XMLDocument and pick out all the relevant stuff.

You can just receive an XmlNode, and that would work fine. Remember that
XmlDocument inherits from XmlNode, and most of the useful methods for
querying are in XmlNode anyway.

That said, you could also very simply create a structure that has that info
and let XmlSerialization deal with it. That would give you a simple object
model to deal with instead of the raw xml.
 
T

Tony C

Thanks for that I thought about using a structure but the only problem
I envisaged was that there <Commands> section is variable, and could
contain 10, 20, 34 etc.. so if I used your suggestion how would that
work.
If i created a <command> structure within a <player> structure when it
arrived would it contain the correct numnber of elements, or do i have
to specify at design time, that a <player> structure contains say a
maximum of 40 <command> structures.

Thanks

Tony
 
T

Tomas Restrepo \(MVP\)

Hi Tony,
Thanks for that I thought about using a structure but the only problem
I envisaged was that there <Commands> section is variable, and could
contain 10, 20, 34 etc.. so if I used your suggestion how would that
work.
If i created a <command> structure within a <player> structure when it
arrived would it contain the correct numnber of elements, or do i have
to specify at design time, that a <player> structure contains say a
maximum of 40 <command> structures.

No, no problem. It's just an array, that's all. Here's a simple example of
what I mean (in C#, but should be a breeze to convert to VB), that also
shows how to use the Xml Serialization attributes to tweak the conversion
process a little:

using System.Xml;
using System.Xml.Serialization;
using System.Web.Services.Protocols;

[ XmlType(Namespace="http://whatever.ns.i.want.org/") ]
[ XmlRoot("Player", Namespace="http://whatever.ns.i.want.org/") ]
public class Player
{
public PlayerInformation Information;


public Command[] Commands;
}

public class PlayerInformation
{
public string PlayerID;
public string PlayerName;
}

public class Command
{
[ XmlAttribute() ]
public string CurPos;
[ XmlAttribute() ]
public string NewPos;
[ XmlAttribute() ]
public string Colour;
[ XmlText ]
public string Value;
}



[ WebMethod ]
[ SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare) ]
public void WhateverMethod(Player player)
{
// do what you want.
}


Nifty, isn't it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top