6 Replies Latest reply: Dec 11, 2012 5:12 AM by SolHill RSS

    consuming a web service using UTL_HTTP, Complex XML types

    SolHill
      this is the first time i have encountered a complex type calling a web service from PLSQL. i have sucsessfully called other methods from this same web service so i know its working.

      this is what i have to pass in:

      <xs:complexType name="AddJobRequestStructure">
      <xs:sequence>
      <xs:element name="AffectedUnits" type="ro:UnitIdentificationStructureArray" />
      <xs:element name="ServiceCode" type="xs:string" />
      <xs:element name="RecordTypeCode" type="xs:string" />
      <xs:element name="MultipleDescriptionCodes" type="ro:DescriptionSeverityStructureArray" />
      </xs:sequence>
      </xs:complexType>

      concentraiting on the parameter "AffectedUnits" type =

      <xs:complexType name="UnitIdentificationStructure">
      <xs:sequence>
      <xs:element name="UnitID" type="xs:string" />
      <xs:element name="StreetID" type="xs:string" />
      <xs:element name="UniqueStreetReferenceNumber" type="xs:string" />
      <xs:element name="UnitNumber" type="xs:string" />
      <xs:element name="Location" type="xs:string" />
      <xs:element name="PAON" type="ro:AONstructure" />
      <xs:element name="Easting" type="xs:double" />
      <xs:element name="Northing" type="xs:double" />
      </xs:sequence>
      </xs:complexType>

      for simple types i build the XML such as:

      request.body := request.body||'<ServiceCode xsi:type="xs:string">'||some_value||'</ServiceCode>';
      (request being a type that holds the namespace,method,body and envelope tag)

      just to re-itterate, i have other web service methods (from the same web service) working this way, however im not sure where to start with this complex type, so any help would be great
      Cheers.
        • 1. Re: consuming a web service using UTL_HTTP, Complex XML types
          odie_63
          So, I guess you have to build an XML fragment that conforms to the complexType definition?

          What have you tried so far?
          There's not much difference from building a simpleType instance as you're currently doing.

          As the XML schema suggests, there's probably an intermediate type you're not showing here :

          "ro:UnitIdentificationStructureArray" --> (sequence of "UnitIdentificationStructure" ?) --> UnitIdentificationStructure

          That means you may have to generate multiple records from whatever data source you use.

          I can't say much more with so few details.

          I consider the approach to be flawed anyway since you can potentially generate invalid XML by not escaping element values.

          Oracle implements XML publishing functions from the SQL/XML standard, I suggest you make use of them instead.
          Combine that with a registered XML schema and you'll get a scalable and self-validating envelope generator that conforms to the expected schema.
          • 2. Re: consuming a web service using UTL_HTTP, Complex XML types
            Billy~Verreynne
            If the question is how to make sense of a WSDL of a web service, then my advice is, don't. Especially if you're not a big fan of XML like me. (the only sane implementation of XML I have ever used was with Microsoft 's SAPI5, for defining grammar files)

            Instead use something like SOAPUI to make sense of that WSDL and generate a sample SOAP template for you.
            • 3. Re: consuming a web service using UTL_HTTP, Complex XML types
              SolHill
              Thanks for the response, I’m not familiar with XML or web services so I appreciate the input. There is indeed an intermediate type. The web service documentation I have does state that the complex type can take multiple records, however we will only ever be passing one, it was this mention of an array that threw me, i asumed the array was the complex type - rather than there being an array of complext types for the handling of multiple records.

              <xs:complexType name="UnitIdentificationStructureArray">
              <xs:complexContent>
              <xs:restriction base="soapenc:Array">
              <xs:sequence />
              <xs:attribute ref="soapenc:arrayType" n1:arrayType="ro:UnitIdentificationStructure[]" xmlns:n1="http://schemas.xmlsoap.org/wsdl/" />
              </xs:restriction>
              </xs:complexContent>
              </xs:complexType>

              I assumed I had to pass each element of the complex type in separately and then reference this somehow in the parent, but it sound like, from what you say, I can just pass in XML containing the data in the correct structure

              Could you give me a basic example of how this XML fragment might look?

              Apologies for the lack of understanding - XML is failry new to me, this is as far as i have got
              Cheers
              • 4. Re: consuming a web service using UTL_HTTP, Complex XML types
                SolHill
                is it as simple as passing this in?

                <affectedunits>
                <UnitID>some data</UnitID>
                <StreetID>some data</StreetID>
                <UniqueStreetReferenceNumber>some data</UniqueStreetReferenceNumber>
                <UnitNumber>some data</UnitNumber>
                <Location>some data</Location>
                <PAON>some data</PAON>
                <Easting>some data</Easting>
                <Northing>some data</Northing>
                </affectedunits>

                (im not in a position to test this at the moment)

                Cheers
                • 5. Re: consuming a web service using UTL_HTTP, Complex XML types
                  Carlovski
                  Yes, what you will pass in is just going to be a single document - the details of the complex type etc are just for the XML validation. It MIGHT help to think about the detailed breakdown of the document for how to design the code if you want to take a modular approach to this (And you might need to handle multiple records in the future).
                  Billy's advice is good though - let SOAPUI handle the intricacies of the complex types, and just mimic the 'Flat' example request document it generates for you.
                  • 6. Re: consuming a web service using UTL_HTTP, Complex XML types
                    SolHill
                    Thanks for the reply

                    Just testing at the moment and cutting my teeth with web services. The final solution will be far more robust. SOAPUI looks good ill be giving downloading it as soon as there download link is back up....

                    I think I have enough understanding now to get some test code together, i appreciate the information you have all provided.

                    Cheers

                    Edited by: SolHill on 11-Dec-2012 03:12