By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

Accessing raw XML in a web service using ASP.Net 2.0

P: n/a
I am defining a web service to receive data that represents an
application form and that returns a message indicating if the
application form has been successfully validated or not, listing any
errors.

I would like to use XPath to define the validation rules that will be
executed within the web service. Clearly, to do this my data has to be
in XML format.

However, I would like my WSDL to describe explicitly the schema of the
application form. i.e. I don't want to use XMLElement or XMLNode as
the input parameter type, as this will not provide my subscribers with
any information on how they should format their submissions.

I suspect that the only way that I am going to achieve this by writing
a soap extension.

Before I get lost in code, can someone confirm that I will be able to
achieve my aims using a soap extension class. Is there a better way of
doing this? Does anyone have any clear samples or walk-throughs?

For clarity, my requirements are:
- to have access to the submitted data in its raw XML form from within
the service implementation (to allow XPath querying).
- I don't want to re-serialize data that ASP.Net has already
deserialized for me!
- WSDL for the service that explicitly describes my schema

Any advice gratefully received.

Sep 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Sandy" <sa*********@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
>I am defining a web service to receive data that represents an
application form and that returns a message indicating if the
application form has been successfully validated or not, listing any
errors.

I would like to use XPath to define the validation rules that will be
executed within the web service. Clearly, to do this my data has to be
in XML format.

However, I would like my WSDL to describe explicitly the schema of the
application form. i.e. I don't want to use XMLElement or XMLNode as
the input parameter type, as this will not provide my subscribers with
any information on how they should format their submissions.

I suspect that the only way that I am going to achieve this by writing
a soap extension.
You don't need a SOAP extension for this! Just create the schema for the
application form, use it in a hand-generated WSDL, and _then_ use XMLElement
parameters.

You don't need to be a slave to the server stub code generated by WSDL.EXE.
You can totally ignore it if you don't need access to any of the data types
it contains. Otherwise, you can use it in your code, but only for the data
types, not for the definitions it contains of the operations in your web
service.

You then define your web service class as inheriting directly from
System.Web.Services.WebService, not from the server stub. There's an article
on this somewhere on MSDN, but I'm afraid I couldn't find it just now.
Here's the definition of one of the more useful web methods in a web service
I'm developing (names changed to protect my job):

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

/// <summary>
/// A service demonstrating the use of Ping
/// </summary>
[WebService(
Name = "PingService",
Description=" A service demonstrating the use of Ping",
Namespace = "urn:base")]
[SoapDocumentService(
SoapBindingUse.Literal,
SoapParameterStyle.Bare,
RoutingStyle = SoapServiceRoutingStyle.RequestElement)] // ws-i
Basic Profile 1.1 Requirement R1109
public class Service : WebService
{

#region Operations
/// <remarks/>
[WebMethod()]
[SoapDocumentMethod("",
Use=SoapBindingUse.Literal,ParameterStyle=SoapPara meterStyle.Bare)]
[return : XmlElement("pingResponse", Namespace="urn:messageTypes.base")]
public XmlElement Ping(
[XmlAnyElement("pingRequest", Namespace="urn:messageTypes.base")]
XmlElement pingRequest)
{
return pingRequest;
}
#endregion
}

Where the request (and response) parameters are defined as follows:

<xs:complexType name="PingContents">
<xs:sequence>
<xs:any namespace="##any" processContents="skip" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
Good Luck,
John
Sep 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.