Importing xsd into wsdl - web-services

This is my current configuration:
XSD
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://stock.com/schemas/services/stock"
xmlns:tns="http://stock.com/schemas/services/stock"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="http://stock.com/schemas/services/stock">
<xsd:element name="Stock">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ticker" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="quotes" nillable="true" type="Quote"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="Quote">
........
</xsd:complexType>
.......
<xsd:element name="gethighBetaStockResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="stock" ref="Stock" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
WSDL
<?xml version="1.0" encoding="UTF-8"?><definitions targetNamespace="http://stock.com/schemas/services/stock/wsdl"
.....xmlns:external="http://stock.com/schemas/services/stock"
<import namespace="http://stock.com/schemas/services/stock" location="Stock.xsd" />
<message name="getStockQuoteResp">
<part name="parameters" element="external:getStockQuoteResponse" />
</message>
However,the moment ref="Stock" is changed to type="Stock",the wsdl2java starts giving
Type {http://stock.com/schemas/services/stock}Stock is referenced but not defined.
Somehow it seems a clash between wsdl and xsd imports - but I just cant resolve it.Help is appreciated.

You have a couple of problems here.
First, the XSD has an issue where an element is both named or referenced; in your case should be referenced.
Change:
<xsd:element name="stock" ref="Stock" minOccurs="1" maxOccurs="unbounded"/>
To:
<xsd:element name="stock" type="Stock" minOccurs="1" maxOccurs="unbounded"/>
And:
Remove the declaration of the global element Stock
Create a complex type declaration for a type named Stock
So:
<xsd:element name="Stock">
<xsd:complexType>
To:
<xsd:complexType name="Stock">
Make sure you fix the xml closing tags.
The second problem is that the correct way to reference an external XSD is to use XSD schema with import/include within a wsdl:types element. wsdl:import is reserved to referencing other WSDL files. More information is available by going through the WS-I specification, section WSDL and Schema Import. Based on WS-I, your case would be:
INCORRECT: (the way you showed it)
<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="http://stock.com/schemas/services/stock/wsdl"
.....xmlns:external="http://stock.com/schemas/services/stock"
<import namespace="http://stock.com/schemas/services/stock" location="Stock.xsd" />
<message name="getStockQuoteResp">
<part name="parameters" element="external:getStockQuoteResponse" />
</message>
</definitions>
CORRECT:
<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="http://stock.com/schemas/services/stock/wsdl"
.....xmlns:external="http://stock.com/schemas/services/stock"
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://stock.com/schemas/services/stock" schemaLocation="Stock.xsd" />
</schema>
</types>
<message name="getStockQuoteResp">
<part name="parameters" element="external:getStockQuoteResponse" />
</message>
</definitions>
SOME processors may support both syntaxes. The XSD you put out shows issues, make sure you first validate the XSD.
It would be better if you go the WS-I way when it comes to WSDL authoring.
Other issues may be related to the use of relative vs. absolute URIs in locating external content.

import vs. include
The primary purpose of an import is to import a namespace. A more common use of the XSD import statement is to import a namespace which appears in another file. You might be gathering the namespace information from the file, but don't forget that it's the namespace that you're importing, not the file (don't confuse an import statement with an include statement).
Another area of confusion is how to specify the location or path of the included .xsd file: An XSD import statement has an optional attribute named schemaLocation but it is not necessary if the namespace of the import statement is at the same location (in the same file) as the import statement itself.
When you do chose to use an external .xsd file for your WSDL, the schemaLocation attribute becomes necessary. Be very sure that the namespace you use in the import statement is the same as the targetNamespace of the schema you are importing. That is, all 3 occurrences must be identical:
WSDL:
xs:import namespace="urn:listing3" schemaLocation="listing3.xsd"/>
XSD:
<xsd:schema targetNamespace="urn:listing3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Another approach to letting know the WSDL about the XSD is through Maven's pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-sources-xmlbeans</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<version>2.3.3</version>
<inherited>true</inherited>
<configuration>
<schemaDirectory>${basedir}/src/main/xsd</schemaDirectory>
</configuration>
</plugin>
You can read more on this in this great IBM article. It has typos such as xsd:import instead of xs:import but otherwise it's fine.

Related

Convert schema-aware stylesheet

I have a schema-aware XSLT transformation that works well. However, the anticipated users of the XSLT will likely not have access to a schema-aware processor. Thus, I'd like to write some code that will convert my schema-aware XSLT into an XSLT that can be used by basic level conforming processors.
For my purposes, the use of schema-aware constructs is limited to matching templates, i.e.
<xsl:template match="element(*, Candidate)">...</>
I'm not expecting this to be a fully automatic process. What I would like is to generate an XSLT that would, for every complexType in an XSD, find its use in a specified surfaced XSD element.
Example code:
<xsd:schema xmlns="example.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="example.xsd" elementFormDefault="qualified" version="0.0">
<xsd:element name="Candidate" type="Candidate"/>
<xsd:complexType name="Candidate">
<xsd:sequence>
<xsd:element name="Code" type="Code" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="Name" type="xsd:string" minOccurs="0"/>
<xsd:element name="PartyId" type="Code" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Code">
<xsd:sequence>
<xsd:element name="Value" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
The expected output for the element Candidate would be something like this:
<complexType_usages>
<usage complexType="Code" path="Candidate/Code" />
<usage complexType="Code" path="Candidate/Party" />
</complexType_usages>
It might be simplest to work from a validated instance rather than trying to analyse the schema (so long as the instance is sufficiently representative). For every element, output the type annotation (using saxon:type-annotation) and the path, then take the list of type/path pairs, and eliminate duplicates and redundancy.

Raw SOAP Magento Requests

Im trying to find information on how to post data to Magento 1.9 SOAP API using PAW / POSTMAN.
Most importantly Im trying to find out how to add filters into the requests
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<soapenv:Header/>
<soapenv:Body>
<urn:salesOrderList soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sessionId xsi:type="xsd:string">alreadydefinedandworking</sessionId>
</urn:salesOrderList>
</soapenv:Body>
</soapenv:Envelope>
Im currently using Soap UI to do my tasks but im stuck on how to add filters into the SOAP packets so I can get data out of Magento.
Is there any location online with Gists for the basics on connecting to Magento using the XML packets? Or if anyone knows how to add the filter in for incremental_id that would be super nice of you
request nodes differ depending on what type of soap API you use in Magento.
There are:
Soap v1
Soap v2
WS-I
if you use the most compatible WSI mode - request param definition looks like this:
<xsd:element name="salesOrderListRequestParam">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string"/>
<xsd:element minOccurs="1" maxOccurs="1" name="filters" type="typens:filters"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
where filters ns is:
<xsd:complexType name="filters">
<xsd:sequence>
<xsd:element name="filter" type="typens:associativeArray" minOccurs="0"/>
<xsd:element name="complex_filter" type="typens:complexFilterArray" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
both values are array-objects with key value pairs.
For more info see the code in API Helper, method: parseFilters() and _parseComplexFilter if you use conditions in filter.
some example (Soap_v2):
<ns1:salesOrderListRequestParam>
<sessionId>your sesion id</sessionId>
<filters>
<filter>
<complexObjectArray>
<key>increment_id</key>
<value>12345</value>
</complexObjectArray>
</filter>
</filters>
</ns1:salesOrderListRequestParam>

SOAP WSDL Error: src-resolve.4.2: Error resolving component 'soapenc:Array.'

Below is a snippet of my wsdl that I'm having an issue with.
This is working, but I'm getting a validation error.
src-resolve.4.2: Error resolving component 'soapenc:Array.' It was detected that 'soapenc:Array' is in namespace 'schemas.xmlsoap.org/soap/encoding/';, but components from this namespace are not referenceable from schema document.
I added this to definitions in my wsdl: xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
<xsd:complexType name="getSalesTaxInformation_Array">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:sequence>
<xsd:element name="productTax" type="tns:getSalesTaxInformation"
maxOccurs="unbounded" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
What does this error mean and how do I get rid of it?
After a bit of digging, I figured it out. The error went away after I added these inside my schema element.
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
I don't know where I found the solution, but here's some information about using the Array thing in the wsdl.
https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Writing_WSDL_Contracts/files/WSDLDefiningArrays.html

XSLT stylesheet for creating an XML Schema Definition

My input data looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:queryResponse xmlns:ns1="http://abc.com/">
<ns1:result>
<ns1:records xmlns:ns2="http://def.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:Account">
<ns2:Id>2c</ns2:Id>
<ns2:Number>A722</ns2:AccountNumber>
</ns1:records>
</ns1:result>
</ns1:queryResponse>
I need to write a stylesheet which will create XML of the format:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Account">
<xsd:sequence>
<xsd:element minOccurs="0" name="Id" type="xsd:string"/>
<xsd:element minOccurs="0" name="Number" type="xsd:string">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
The stylesheet should be able to create this XML?
The fields are also dynamically changing, so the stylesheet has to be generic so that it can extract the element name and value from the XML and create the output XML.

xs:choice embedded in xs:sequence prevents the use of a union

I have the following xsd
<xsd:complexType name="myID">
<xsd:choice>
<xsd:element name="testID" type="priv:testID"/>
<xsd:sequence>
<xsd:element name="newID" type="priv:newID"/>
<xsd:element name="testID" type="priv:testID" minOccurs="0"/>
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
Everything is under priv namespace. The problem is that it looks like that myID is a union. It might be a testID or a sequence with newID and testID. When I compile it with wsdl2h from gsoap I am taking the message:
Note: <xs:choice> with embedded
<xs:sequence> or <xs:group>
prevents the use of a union
Is the above XSD correct?
In general the XML type myID can be declared as you described. The conflict exist probably in connection with your definition of the types priv:testID and priv:testID which definition you not included. For example the schema
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="http://www.ok-soft-gmbh.com/xml/xsd/1.0/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns:priv="http://www.ok-soft-gmbh.com/xml/xsd/1.0/XMLSchema.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsd:simpleType name="testID">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:simpleType name="newID">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:complexType name="myID">
<xsd:choice>
<xsd:element name="testID" type="priv:testID"/>
<xsd:sequence>
<xsd:element name="newID" type="priv:newID"/>
<xsd:element name="testID" type="priv:testID" minOccurs="0"/>
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
<xsd:element name="root" type="priv:myID"/>
</xsd:schema>
will be correct. So if an error exist, it is not in the part which you posted.