Adding an XmlNode parameter to the HelloWorld WebMethod

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default Adding an XmlNode parameter to the HelloWorld WebMethod

    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 Guest

  2. Similar Questions and Discussions

    1. WebMethod signature which takes SortedList as parameter??
      SortedList is a .NET class and shouldn't be used as a parameter to a Webmethod. I just posted earlier today discussing why things like this aren't...
    2. Adding a new WebMethod , what about old client?
      If I add a new webMethod in my WebService, does this web service will continue to work fine with older client? Tks
    3. WebMethod + MaxOccurs for input parameter; possible?
      Good afternoon everyone, I have a WebMethod function (VB .NET) that receive a parameter (Order #). I would like to be able to change my function...
    4. [WebMethod] passing, receving XmlNode Without a Namespace
      Hi all, For some reasons I sometimes use the following interface for xml passing: public XmlNode getSomeOutputXml(XmlNode someInputXml) { }...
    5. DataTable parameter of a WebMethod?
      DataTable is not serializable, you have to put them in a dataset. DataTable object to it. I visit the .asmx can't pass in a...
  3. #2

    Default Re: Adding an XmlNode parameter to the HelloWorld WebMethod

    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 Guest

  4. #3

    Default Re: Adding an XmlNode parameter to the HelloWorld WebMethod

    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 [email]X@hotmail.com[/email]> 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?
    > >
    > >
    >
    >

    Brad Quinn Guest

  5. #4

    Default Re: Adding an XmlNode parameter to the HelloWorld WebMethod

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

    [System.Xml.Serialization.XmlElementAttribute("Clas s1", typeof(Class1))]
    [System.Xml.Serialization.XmlElementAttribute("Clas s2", 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 [email]X@hotmail.com[/email]> 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 Guest

  6. #5

    Default Re: Adding an XmlNode parameter to the HelloWorld WebMethod

    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("Clas s1",
    typeof(Class1))]
    > [System.Xml.Serialization.XmlElementAttribute("Clas s2",
    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 [email]X@hotmail.com[/email]> 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("Clas s1", typeof(Class1))]
    > > [System.Xml.Serialization.XmlElementAttribute("Clas s2", 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/>
    >
    >

    Lucien Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139