Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Automatic WSDL generation

Automatic WSDL generation

Scheduled Pinned Locked Moved C#
xmldatabasewcfregexjson
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kentamanos
    wrote on last edited by
    #1

    I'm trying to develop an XML Webservice for work that uses SOAP. It's very easy to get something going quickly, but It's a bit tougher to get it exactly like you want ;). My current concern is the WSDL that's automatically generated with the "?WSDL" query string is very unstrict (can't blame it, it's not psychic). For instance, every parameter to a method that can be null ends up having its "minOccurs" set to 0. I'd also really like to be able to use some regular expression restrictions for certain types. I'm a big believer in schema validation (which I realize I have to do by hand regardless of what the WSDL says), and I'd like the WSDL to be more strict. I've searched for quite a while, and I'm not having much luck finding anything. There seems to be a lot of attributes I can use to control the XML serialization of classes, but I haven't seen anything yet that lets me do something like "represent this class with this XmlSchema instance", which might be how I would get my service to create a "good" schema (guessing here). Should I just give up on making the automatically generated WSDL look good and just write my own WSDL file by hand (and point clients there). It seems like that route would be more of a pain in the butt to maintain, but if that's the only way to make me happy I might go that route. Is there any way I can turn off the automatic WSDL generation (?WSDL querystring on the .asmx) if I go that route?


    I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
    -David St. Hubbins

    K H 2 Replies Last reply
    0
    • K Kentamanos

      I'm trying to develop an XML Webservice for work that uses SOAP. It's very easy to get something going quickly, but It's a bit tougher to get it exactly like you want ;). My current concern is the WSDL that's automatically generated with the "?WSDL" query string is very unstrict (can't blame it, it's not psychic). For instance, every parameter to a method that can be null ends up having its "minOccurs" set to 0. I'd also really like to be able to use some regular expression restrictions for certain types. I'm a big believer in schema validation (which I realize I have to do by hand regardless of what the WSDL says), and I'd like the WSDL to be more strict. I've searched for quite a while, and I'm not having much luck finding anything. There seems to be a lot of attributes I can use to control the XML serialization of classes, but I haven't seen anything yet that lets me do something like "represent this class with this XmlSchema instance", which might be how I would get my service to create a "good" schema (guessing here). Should I just give up on making the automatically generated WSDL look good and just write my own WSDL file by hand (and point clients there). It seems like that route would be more of a pain in the butt to maintain, but if that's the only way to make me happy I might go that route. Is there any way I can turn off the automatic WSDL generation (?WSDL querystring on the .asmx) if I go that route?


      I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
      -David St. Hubbins

      K Offline
      K Offline
      Kentamanos
      wrote on last edited by
      #2

      Hmmm...looks like I might be able to implement IXmlSerializable and have it return the exact schema. I'm going to check that out...


      I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
      -David St. Hubbins

      K 1 Reply Last reply
      0
      • K Kentamanos

        Hmmm...looks like I might be able to implement IXmlSerializable and have it return the exact schema. I'm going to check that out...


        I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
        -David St. Hubbins

        K Offline
        K Offline
        Kentamanos
        wrote on last edited by
        #3

        Well just in case someone's following my rambling... I hate when I figure something out minutes after I posted :). I spent the most of the day going down the wrong path with all the attributes available for classes that control how XML serialization works. It would appear that at the end of the day, you're better off just going ahead and implementing IXmlSerializable yourself and saving yourself a lot of headaches. I now need to make sure the proxy generators handle this type of WSDL properly (I doubt classes will enforce restrictions, but at least I'm putting it out there as a "contract" for clients). If the proxy generators (one in IDE and WSDL.exe if nothing else) handle this properly, then I should be set.


        I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
        -David St. Hubbins

        1 Reply Last reply
        0
        • K Kentamanos

          I'm trying to develop an XML Webservice for work that uses SOAP. It's very easy to get something going quickly, but It's a bit tougher to get it exactly like you want ;). My current concern is the WSDL that's automatically generated with the "?WSDL" query string is very unstrict (can't blame it, it's not psychic). For instance, every parameter to a method that can be null ends up having its "minOccurs" set to 0. I'd also really like to be able to use some regular expression restrictions for certain types. I'm a big believer in schema validation (which I realize I have to do by hand regardless of what the WSDL says), and I'd like the WSDL to be more strict. I've searched for quite a while, and I'm not having much luck finding anything. There seems to be a lot of attributes I can use to control the XML serialization of classes, but I haven't seen anything yet that lets me do something like "represent this class with this XmlSchema instance", which might be how I would get my service to create a "good" schema (guessing here). Should I just give up on making the automatically generated WSDL look good and just write my own WSDL file by hand (and point clients there). It seems like that route would be more of a pain in the butt to maintain, but if that's the only way to make me happy I might go that route. Is there any way I can turn off the automatic WSDL generation (?WSDL querystring on the .asmx) if I go that route?


          I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
          -David St. Hubbins

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          There's a ton of attributes you can use to control a lot of this, although I'm not sure about the regex, and don't remember ever seeing anything like this - but you shouldn't rely stricly on WSDL schema validation since some clients may not do that. Always check params going into your code, so you ultimately control what goes in and out of your methods! First, there's the attributes in the System.Xml.Serialization namespace, like the XmlRootAttribute and XmlElementAttribute that have an IsNullable property you can set to false. There's also many advanced usage attributes in System.Web.Services.Protocols that let you control the input and output of SOAP and help in the documentation generation for the WSDL, such as using different readers and writers for the generation using the HttpMethodAttribute. You should use these when you can because it ultimately gives you more control over SOAP and WSDL, and IXmlSerialization is not supposed to be used from your code which means it could change at any time without notice (but I must confess I've used it a few times here and there! :)).

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          K 1 Reply Last reply
          0
          • H Heath Stewart

            There's a ton of attributes you can use to control a lot of this, although I'm not sure about the regex, and don't remember ever seeing anything like this - but you shouldn't rely stricly on WSDL schema validation since some clients may not do that. Always check params going into your code, so you ultimately control what goes in and out of your methods! First, there's the attributes in the System.Xml.Serialization namespace, like the XmlRootAttribute and XmlElementAttribute that have an IsNullable property you can set to false. There's also many advanced usage attributes in System.Web.Services.Protocols that let you control the input and output of SOAP and help in the documentation generation for the WSDL, such as using different readers and writers for the generation using the HttpMethodAttribute. You should use these when you can because it ultimately gives you more control over SOAP and WSDL, and IXmlSerialization is not supposed to be used from your code which means it could change at any time without notice (but I must confess I've used it a few times here and there! :)).

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            K Offline
            K Offline
            Kentamanos
            wrote on last edited by
            #5

            I know that the web services don't do any sort of validation, and that I'll have to create a handler to do the validation in any event. I just want WSDL that makes sense and is tight as possible, but I'm starting to think that getting it as tight as I would like will be impossible (I'm a big fan of very explicit "contracts"). Implementing IXmlSerializable made the proxy generator (IDE and WSDL.exe) fail to generate anything for data types I tried to define myself. That means we'd have to give them assemblies for those classes or they'd have to write their own class. So I think going the attributes route is definitely the way to go again, and I'll just have to not expect too much from the WSDL :). I actually didn't even notice the IXmlSerializable interface was not supposed to be used. I saw the suggestion in a post (and if I remember correctly it was from a MS VIP or a MS employee). You're right though, it shouldn't really be used. I missed that IsNullable property. A co-worker claims to have used that and still gets a "minOccurs=0", but I'll check that out in any case. Thanks for the help!


            I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
            -David St. Hubbins

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups