[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Adding an XmlNode parameter to the HelloWorld WebMethod

Brad Quinn

7/31/2003 7:49:00 PM

I've added an XmlNode as a parameter to the HelloWorld WebMethod. The
automaticall generated WSDL would leave one to believe that any well-formed
XML is valid.

But let's say that you expected that node to conform to some schema. How do
you get the WSDL to convey that fact. Is there a way to "hack" the WSDL?


4 Answers

Lucien

7/31/2003 10:58:00 PM

0

Any well-formed XML *is* valid since you defined XmlNode as the schema so
that's
what you get in the WSDL. If you need a more 'restrictive' schema define a
class.

"Brad Quinn" <brad_quinn@yahoo.com> wrote in message
news:uX5hQz5VDHA.624@TK2MSFTNGP10.phx.gbl...
> I've added an XmlNode as a parameter to the HelloWorld WebMethod. The
> automaticall generated WSDL would leave one to believe that any
well-formed
> XML is valid.
>
> But let's say that you expected that node to conform to some schema. How
do
> you get the WSDL to convey that fact. Is there a way to "hack" the WSDL?
>
>


Brad Quinn

8/1/2003 12:53:00 PM

0

One problem with this is that a schema is more rigorous than a class. For
instance;

Lets say I generate a class from a schema using xsd. I now use this class
as a parameter to my web service. The wsdl that is generated will allow XML
that the original schema would have rejected. This is easy to see when
using <xs:choice ...> with minOccurs and maxOccurs.

Is there a way to tweak (or outright specify completely) the wsdl of a
WebService?

"Lucien" <Xlucienen X@hotmail.com> wrote in message
news:3f299f01$1@news.microsoft.com...
> Any well-formed XML *is* valid since you defined XmlNode as the schema so
> that's
> what you get in the WSDL. If you need a more 'restrictive' schema define a
> class.
>
> "Brad Quinn" <brad_quinn@yahoo.com> wrote in message
> news:uX5hQz5VDHA.624@TK2MSFTNGP10.phx.gbl...
> > I've added an XmlNode as a parameter to the HelloWorld WebMethod. The
> > automaticall generated WSDL would leave one to believe that any
> well-formed
> > XML is valid.
> >
> > But let's say that you expected that node to conform to some schema.
How
> do
> > you get the WSDL to convey that fact. Is there a way to "hack" the
WSDL?
> >
> >
>
>


Lucien

8/1/2003 3:54:00 PM

0

You can express a choice in a class. Use attributes like this:

[System.Xml.Serialization.XmlElementAttribute("Class1", typeof(Class1))]
[System.Xml.Serialization.XmlElementAttribute("Class2", typeof(Class2))]
public object myChoiceClass ...
If there would be a schema definition that you couldn't express in a class
you could create the proxy manually by using the WSDL.exe tool. However most
implementations don't do a full WSDL schema check and it would only fail if
(de)serialize fails. So you'd have to add the check programmatically if you
needed to enforce special constraints.



"Brad Quinn" <brad_quinn@yahoo.com> wrote in message
news:%23fNsPvCWDHA.2212@TK2MSFTNGP12.phx.gbl...
> One problem with this is that a schema is more rigorous than a class. For
> instance;
>
> Lets say I generate a class from a schema using xsd. I now use this class
> as a parameter to my web service. The wsdl that is generated will allow
XML
> that the original schema would have rejected. This is easy to see when
> using <xs:choice ...> with minOccurs and maxOccurs.
>
> Is there a way to tweak (or outright specify completely) the wsdl of a
> WebService?
>
> "Lucien" <Xlucienen X@hotmail.com> wrote in message
> news:3f299f01$1@news.microsoft.com...
> > Any well-formed XML *is* valid since you defined XmlNode as the schema
so
> > that's
> > what you get in the WSDL. If you need a more 'restrictive' schema define
a
> > class.
> >
> > "Brad Quinn" <brad_quinn@yahoo.com> wrote in message
> > news:uX5hQz5VDHA.624@TK2MSFTNGP10.phx.gbl...
> > > I've added an XmlNode as a parameter to the HelloWorld WebMethod. The
> > > automaticall generated WSDL would leave one to believe that any
> > well-formed
> > > XML is valid.
> > >
> > > But let's say that you expected that node to conform to some schema.
> How
> > do
> > > you get the WSDL to convey that fact. Is there a way to "hack" the
> WSDL?
> > >
> > >
> >
> >
>
>


Lucien

8/2/2003 12:02:00 AM

0

The WSDL is not used for schema validation unless you add this yourself (as
a SoapExtension for instance).
You could create a XSD schema and use that for schema validation (or save a
WSDL file and modify it).


"Brad Quinn" <brad_quinn@yahoo.com> wrote in message
news:ujoa0zEWDHA.384@TK2MSFTNGP12.phx.gbl...
> I'm planning on doing schema validation in a SoapExtension.
>
> I want the consumer of my WebService to be forewarned.
>
> Lets say this is the schema fragment that I'm going to validate with;
>
> <xs:complexType name="Class1"> ...
> <xs:complexType name="Class2"> ...
>
> <xs:choice minOccurs="1" maxOccurs="2">
> <xs:element name="Class1" type="Class1" minOccurs="0" maxOccurs="1"
/>
> <xs:element name="Class2" type="Class2" minOccurs="0" maxOccurs="1"
/>
> </xs:choice>
>
> The corresponding field in C# would look like this;
>
> [System.Xml.Serialization.XmlElementAttribute("Class1",
typeof(Class1))]
> [System.Xml.Serialization.XmlElementAttribute("Class2",
typeof(Class2))]
> public object [] myChoiceClass;
>
> But the generated WSDL looks like this, which isn't quite right;
>
> <s:choice minOccurs="0" maxOccurs="unbounded">
> <s:element minOccurs="0" maxOccurs="1" name="Class1"
type="s1:Class1"
> />
> <s:element minOccurs="0" maxOccurs="1" name="Class2"
type="s1:Class2"
> />
> </s:choice>
>
> It looks pretty close, but looks can be deceiving. I could easily modify
> the schema so that the WSDL wouldn't look like it was mostly correct.
>
> "Lucien" <Xlucienen X@hotmail.com> wrote in message
> news:3f2a8d1d$1@news.microsoft.com...
> > You can express a choice in a class. Use attributes like this:
> >
> > [System.Xml.Serialization.XmlElementAttribute("Class1", typeof(Class1))]
> > [System.Xml.Serialization.XmlElementAttribute("Class2", typeof(Class2))]
> > public object myChoiceClass ...
> > If there would be a schema definition that you couldn't express in a
class
> > you could create the proxy manually by using the WSDL.exe tool. However
> most
> > implementations don't do a full WSDL schema check and it would only fail
> if
> > (de)serialize fails. So you'd have to add the check programmatically if
> you
> > needed to enforce special constraints.
> >
>
> <snip/>
>
>