3 Replies Latest reply on Aug 19, 2008 11:16 AM by davidsimms

    Creating Web Services

    AdeptDeveloper
      Hi,

      I'm trying to create a complex webservice with arrays of complex types and the output is undesirable...

      Below is my Internet Component and it has two elements "Website" a string and Zero or More Email objects (i.e. a complex type described by Email.cfc). Notice that the code produced has the <rpc:item> sub element which makes it more difficult for non-cf consumers (which is about 99% of my consumers) to use this web service.

      I would prefer the code to be more like:

      <Internet>
      <Email>
      ... sub elements go here>
      </Email>
      <Email>
      ... sub elements go here>
      </Email>
      <Email>
      ... sub elements go here>
      </Email>
      </Internet>

        • 1. Re: Creating Web Services
          Dan Bracuk Level 5
          Instead of
          "I'm trying to create a complex webservice with arrays of complex types "

          Have you considered a simple webservice instead?

          By the way, you realize that the code you posted doesn't actually do anything, right? Not sure where the produced code comes from.

          • 2. Re: Creating Web Services
            AdeptDeveloper Level 1
            Of course I realize it doesn't "do" anything, it's supposed to generate the WSDL document when accessed via url with the ?WSDL appended. All the functional code is omitted because the problem isn't with application logic, it's with the way CF renders the WSDL. Mabe that wasn't clear. I'm speaking only from the notion of using CF to create the WSDL document. The functional component of the web service isn't an issue.

            A Simple Web Service won't get the job done properly. I need to be able to handle arrays of data because I don't know the extent of data being submitted. In this example, where we are describing an Array of E-mail Addresses, what happens when User A, B and C only have 1 address but User D has 5 e-mails. The system needs to be able to support that in a scalable way. Hence, the desire to have an Array of Email Object Types. It's very common in WSDL development, so CF should be able to support it, but then again, it doesn't seem to support other common features such as Optional Elements, MinOccurs/MaxOccurs (for arrays) and Enumerations.

            -Steve
            • 3. Creating Web Services
              davidsimms Level 1
              Steve,

              I once had a similar situation in which I need the consuming web page to pass into my web service what would become a CF structure. If the consuming web page were itself a CF page, no problem. They would simply pass a CF structure (nothing more but an entire FORM scope in this case) and the web service method could work with it fine. However, if the consuming web page were not CF, it obviously can't pass in a CF structure. In these cases, it would be acceptable for the consumer to parse over the FORM scope and create a simple data object--a text string. That text string would be marked up as valid XML. This text string would be passed in where the CF structure normally would be passed and the web service would sense the data type. In other words, it it were a CF structure, it would process normally, if it weren't a CF structure, it would sense if it were a string, and if yes, is it also a string marked up with valid XML? If yes, it would convert the string to a true XML document object type and parse over that to create guess what--a CF structure exactly like what would have been passed by a CF client.

              Describing it makes it sound more complex than it really is, and in fact, it really doesn't take that much code and it performs beautifully. I investigated extensively other possibilities before deciding on the one above and I know now in retrospect I made the right decision. It's so easy to provide the required XML structure to any type of client (.NET, PHP, etc.) and have them pass in plain text.

              I don't know if that gives you the specific answer you were looking for, but thought I'd share the experience in the hopes it offers some insight into how I handled a similar conundrum.

              David