I'm trying to validate this XML file
<session>
<mic id="1" posname="T1" x="0.0" y="0.0" z="0.0" />
</session>
using this XSD file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:element name="session">
<xs:complexType>
<xs:sequence>
<xs:element name="mic" type="micType" minOccurs="1" maxOccurs="4">
</xs:element>
<xs:complexType name="micType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:int" name="id"/>
<xs:attribute type="xs:string" name="posname"/>
<xs:attribute type="xs:float" name="x"/>
<xs:attribute type="xs:float" name="y"/>
<xs:attribute type="xs:float" name="z"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
but I get this error message:
XmlSchema error: Element http://www.w3.org/2001/XMLSchema:complexType is invalid in this context.
If I just have the attribute definition for the mic element the program runs fine. I don't know what I'm doing wrong. I'm trying to have the XSD validate the data types for the mic element. Can anybody please tell me what I'm doing wrong?
The complexType named micType should be defined as a global type declaration, i.e. it should be an immediate child of the xs:schema element.
What you have is a non-viable hybrid of a local and global declaration of a complex type. Either define a micType globally (as Michael Kay mentioned) or locally:
Global complexType declaration
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:element name="session">
<xs:complexType>
<xs:sequence>
<xs:element name="mic" type="micType" minOccurs="1" maxOccurs="4"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="micType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:int" name="id"/>
<xs:attribute type="xs:string" name="posname"/>
<xs:attribute type="xs:float" name="x"/>
<xs:attribute type="xs:float" name="y"/>
<xs:attribute type="xs:float" name="z"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
Local complexType declaration
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:element name="session">
<xs:complexType>
<xs:sequence>
<xs:element name="mic" minOccurs="1" maxOccurs="4">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:int" name="id"/>
<xs:attribute type="xs:string" name="posname"/>
<xs:attribute type="xs:float" name="x"/>
<xs:attribute type="xs:float" name="y"/>
<xs:attribute type="xs:float" name="z"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Either way is ok and will successfully validate your XML.
A have description of the Web service that I need to implement.
order-processor-Service.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:port="http://xxxx.yy.ru/services/forms/integration/orderprocess"
xmlns:tns="http://xxxx.yy.ru/services/forms/integration/orderprocess"
targetNamespace="http://xxxx.yy.ru/services/forms/integration/orderprocess"
>
<wsdl:import namespace="http://xxxx.yy.ru/services/forms/integration/orderprocess" location="order-processor.wsdl"/>
<wsdl:binding name="OrderProcessorSOAP" type="port:IOrderProcessor">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="processOrder">
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault name="fault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OderProcessorService">
<wsdl:port name="OrderProcessorSoap" binding="tns:OrderProcessorSOAP">
<soap:address location="http://localhost/OrderProcessorService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
order-processor.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:data="http://xxxx.yy.ru/services/forms/integration/orderprocess"
xmlns:tns="http://xxxx.yy.ru/services/forms/integration/orderprocess"
targetNamespace="http://xxxx.yy.ru/services/forms/integration/orderprocess"
>
<wsdl:types>
<xs:schema>
<xs:import namespace="http://xxxx.yy.ru/services/forms/integration/orderprocess" schemaLocation="order-processor.xsd"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="processOrderRequest">
<wsdl:part name="params" element="data:processOrder" />
</wsdl:message>
<wsdl:message name="processOrderResponse">
<wsdl:part name="params" element="data:processOrderResponse" />
</wsdl:message>
<wsdl:message name="OrderProcessorException">
<wsdl:part name="params" element="data:processOrderFault" />
</wsdl:message>
<wsdl:portType name="IOrderProcessor">
<!-- wsdl:portType customizations -->
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
</jaxws:bindings>
<wsdl:operation name="processOrder">
<wsdl:input name="message" message="tns:processOrderRequest" />
<wsdl:output name="return" message="tns:processOrderResponse" />
<wsdl:fault name="fault" message="tns:OrderProcessorException" />
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
order-processor.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xxxx.yy.ru/services/forms/integration/orderprocess"
xmlns:tns="http://xxxx.yy.ru/services/forms/integration/orderprocess"
xmlns:types="http://xxxx.yy.ru/services/forms/integration/types"
elementFormDefault="qualified"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0"
>
<xs:import namespace="http://xxxx.yy.ru/services/forms/integration/types" schemaLocation="forms-services-types.xsd"/>
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:date"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime"
/>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime"
/>
<jaxb:serializable uid="1" />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
<xs:element name="processOrder" type="tns:ProcessOrderRequest" />
<xs:element name="processOrderResponse" type="tns:ProcessOrderResponse" />
<xs:element name="processOrderFault" type="xs:string">
<xs:annotation>
<xs:documentation>
Элемент содержит сообщение об ошибке (то что будет пользователю показываться)
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="ProcessOrderRequest">
<xs:sequence>
<xs:element name="OrderHeader" type="tns:OrderHeader">
<xs:annotation>
<xs:documentation>
Доступная служебная информация о заявке (почти все, что хранится в базе)
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="OrderPayload" >
<xs:annotation>
<xs:documentation>
Модель данных из формы
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:any/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="OrderAttachments" type="tns:OrderAttachments" >
<xs:annotation>
<xs:documentation>
Прикрепленные файлы из формы
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ProcessOrderResponse">
<xs:sequence>
<xs:annotation>
<xs:documentation>
Идентификатор заявки назначенный внешней сиситемой
</xs:documentation>
</xs:annotation>
<xs:element name="return" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="OrderHeader">
<xs:sequence>
<xs:element ref="types:order"/>
<xs:element ref="types:service"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="OrderAttachments">
<xs:sequence>
<xs:element ref="types:attachments" />
</xs:sequence>
</xs:complexType>
</xs:schema>
and forms-services-types.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xxxx.yy.ru/services/forms/integration/types"
xmlns:tns="http://xxxx.yy.ru/services/forms/integration/types"
elementFormDefault="qualified"
>
<xs:element name="order" type="tns:OrderType"/>
<xs:element name="service" type="tns:ServiceType"/>
<xs:element name="attachments" >
<xs:complexType>
<xs:sequence>
<xs:element name="attachment" type="tns:AttachmentType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="OrderType">
<xs:sequence>
<xs:element name="guid" type="xs:string">
<xs:annotation>
<xs:documentation>
внутренний мдентификатор заявки. для служебного пользования
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="humanID" type="xs:string">
<xs:annotation>
<xs:documentation>
идентификатор заявки отображаемый пользователю
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="externalId" type="xs:string">
<xs:annotation>
<xs:documentation>
идентификатор заявки, присваеваемый обрабатывающей сиситемой.
Если система поддерживает наши идентификаторы, то вероятно будет равен guid
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="creationDate" type="xs:dateTime">
<xs:annotation>
<xs:documentation>
дата создаия заявки
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="userId" type="xs:string">
<xs:annotation>
<xs:documentation>
идентификатор пользователя, подавшего заявку
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="serviceId" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceType">
<xs:sequence>
<xs:element name="guid" type="xs:string">
<xs:annotation>
<xs:documentation>
идентификатор услуги
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="name" type="xs:string">
<xs:annotation>
<xs:documentation>
имя услуги
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="orderPrefix" type="xs:string">
<xs:annotation>
<xs:documentation>
префикс для идентификтора заявки данной услуги.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="properties">
<xs:annotation>
<xs:documentation>
свойства специфичные для обработчиков данной услуги
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="property" type="tns:PropertyType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="PropertyType">
<xs:sequence>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="AttachmentType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="mimeType" type="xs:string"/>
<xs:element name="data" type="xs:base64Binary"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
When I try to generate code using wsimport - all good, but when I use wsdl.exe - I get an error:
C:\Documents and Settings\Alex\Рабочий стол\orders-processing>"C:\Program Files\
Microsoft SDKs\Windows\v7.0A\bin\wsdl.exe" /serverInterface order-processor-Serv
ice.wsdl order-processor.wsdl order-processor.xsd forms-services-types.xsd
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: Unable to import binding 'OrderProcessorSOAP' from namespace 'http://xxxx
.yy.ru/services/forms/integration/orderprocess'.
- Unable to import operation 'processOrder'.
- The operation binding 'processOrder' from namespace 'http://xxxx.yy.ru/servi
ces/forms/integration/orderprocess' had invalid syntax. Missing soap:operation
binding.
If you would like more help, please type "wsdl /?".
I need a service implementation for C#, not java.
Please, help me.
The error message
Missing soap:operation binding
implies that you need to use a
<soap:operation soapAction="" />
declaration or similar.
The absence of this declaration can cause the error you are experiencing.
When I run the xsd tool to generate vb classes against:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="Security" type="SecurityType"/>
<xs:complexType name="SecurityType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="UsernameToken" type="UsernameToken"/>
</xs:sequence>
<xs:attribute name="mustUnderstand" type="xs:string"/>
<xs:anyAttribute/>
</xs:complexType>
<xs:complexType name="UsernameToken">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Username" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="Password" type="Password"/>
</xs:sequence>
<xs:attribute name="Id" type="xs:string"/>
</xs:complexType>
<xs:complexType name="Password">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Type" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
I get the following schema validation warnings:
Type Password is not declared
Type UsernameToken is not declared
Type SecurityType is not declared
I get the following Error:
The datatype 'SecurityType' is missing
I added xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" and it worked.
I want to create / infer schema for data-contract serialized classes.
When I use [DataContract(IsReference = true)] attribute the serializer is injecting attributes z:Id="i2" and z:Ref="i2" to reference the same object instances.
Both attributes are from http://schemas.microsoft.com/2003/10/Serialization/ namespace.
Questions:
Is there a xsd schema file for the namespace used by serializer which I could import into my schema?
For now I am defining those attributes as a xs:ID / xs:IDREF pair. Is that correct?
Thanks in advance.
The xsd schema is supposed to described here - look for the section Data Contract Serialization Schema. However, if you do look for your attributes, you will not find them in there - documentation bug!
To get the full schema, take a look at this and this - inside the WSDL types, you'll find the correct schema. As for your assumption regarding the attributes, yes, you are correct.
I am inlining it here, just in case:
<?xml version="1.0"?>
<xs:schema xmlns:tns2="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns2:char"/>
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns2:duration"/>
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns2:guid"/>
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
I have a web-service written in Java, hosted on an Axis2 / Tomcat / Apache server. My client software is written in C#.
I have had a few irritating problems with the way java2wsdl generates the wsdl file, which did cause me a few headaches early on, but with this problem I am completely stumped.
Basically what is happening is that the client sees the web service fine, and sends a perfectly valid (or at least, it looks valid to me) SOAP request with parameters.
On the server, the correct web method is executed, but the parameters are all null. My web service detects this and builds up a response, which the client receives and understands perfectly well.
My hunch is that Axis2 is falling flat on its face somewhere, but given the headaches I have had with java2wsdl, perhaps all I need is a change in my wsdl file.
Here is the wsdl file:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://stws/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http://stws/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://stws/">
<wsdl:types>
<xs:schema xmlns:ns="http://stws/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://stws/xsd">
<xs:element name="GetGroups">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetGroupsResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Group"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Group">
<xs:sequence>
<xs:element minOccurs="0" name="ID" type="xs:int"/>
<xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="GetMessages">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="groupids" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetMessagesResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Message"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Message">
<xs:sequence>
<xs:element minOccurs="0" name="date" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="group" type="xs:int"/>
<xs:element minOccurs="0" name="messageID" type="xs:int"/>
<xs:element minOccurs="0" name="text" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetMessagesRequest">
<wsdl:part name="parameters" element="ns0:GetMessages"/>
</wsdl:message>
<wsdl:message name="GetMessagesResponse">
<wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<wsdl:message name="GetGroupsResponse">
<wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
</wsdl:message>
<wsdl:portType name="MyProjectPortType">
<wsdl:operation name="GetMessages">
<wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
<wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
<wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyProjectSOAP11Binding" type="axis2:MyProjectPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="GetMessages">
<soap:operation soapAction="urn:GetMessages" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<soap:operation soapAction="urn:GetGroups" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="MyProjectSOAP12Binding" type="axis2:MyProjectPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="GetMessages">
<soap12:operation soapAction="urn:GetMessages" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<soap12:operation soapAction="urn:GetGroups" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="MyProjectHttpBinding" type="axis2:MyProjectPortType">
<http:binding verb="POST"/>
<wsdl:operation name="GetMessages">
<http:operation location="MyProject/GetMessages"/>
<wsdl:input>
<mime:content type="text/xml" part="GetMessages"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="GetMessages"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<http:operation location="MyProject/GetGroups"/>
<wsdl:input>
<mime:content type="text/xml" part="GetGroups"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="GetGroups"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyProject">
<wsdl:port name="MyProjectSOAP11port_http" binding="axis2:MyProjectSOAP11Binding">
<soap:address location="http://localhost:8080/axis2/services/MyProject"/>
</wsdl:port>
<wsdl:port name="MyProjectSOAP12port_http" binding="axis2:MyProjectSOAP12Binding">
<soap12:address location="http://localhost:8080/axis2/services/MyProject"/>
</wsdl:port>
<wsdl:port name="MyProjectHttpport" binding="axis2:MyProjectHttpBinding">
<http:address location="http://localhost:8080/axis2/services/MyProject"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
And here is a sample request and response:
Request:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetGroups xmlns="http://stws/xsd">
<serialcode>123456-654321</serialcode>
</GetGroups>
</soap:Body>
</soap:Envelope>
Response
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<GetGroupsResponse xmlns="http://stws/xsd">
<return>
<ID>-101</ID>
<name>ERROR: Empty Serial</name>
</return>
</GetGroupsResponse>
</soapenv:Body>
</soapenv:Envelope>
Does anybody have any idea what could be going wrong?
The error message in the response can only be sent when the serialcode parameter in the request is empty / null, so I'm guessing there is something wrong with how Axis2 is reading my parameters.
============================================================
How to fix this:
This is in response to Aldo's request for more information about how I fixed this problem.
I am unsure of why this fix works - perhaps it is just a bug in Axis2 or something. Either way, YMMV as I don't know whether the problem was caused by my setup or something else. All I can say is that by doing the following, everything started working.
Anyway, the auto-generated WSDL file creates complex-element types for web requests and their parameters, even when the only parameters are simple types such as strings or integers. What I did was go through and create the correct simple-type tags for parameters (such as 'serialcode' or 'date-string'), then replace the references to the complex types elsewhere in the WSDL file with references to the simple types.
An example is below:
Auto Generated WSDL method and parameters
<!--Requests-->
<wsdl:message name="RegisterClientRequest">
<wsdl:part name="parameters" element="ns0:RegisterClient"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<!--Parameters-->
<xs:element name="RegisterClient">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetGroups">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Basically what you should do is discard the auto-generated parameters and create simple-types. You then modify the 'request' tags to use 'type' rather than 'element', and use your newly created simple-types.
Modified / Fixed WSDL
<!--Requests-->
<wsdl:message name="RegisterClientRequest">
<wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>
<!--Parameters-->
<xs:simpleType name="SerialCode">
<xs:restriction base="xs:string"/>
</xs:simpleType>
Obviously it depends on what your parameters actually are. In my case they are all standard simple types such as strings and integers. If you are passing more than one parameter, you may need to play around by retaining the auto-generated elements but making sure that the element refers to simple types rather than just including the type attribute as 'xs:string' or something of that nature.
Apologies I can't be more clear on this, but as I said earlier - I don't know why this works.
One final thing: By removing the 'element' reference attribute in the request tags - you may receive a parser warning in your Axis2 logs. So far this has not caused me any problems, but it's something to be aware of in case you run into trouble.
I solved this issue by going through my WSDL file and, wherever possible, breaking down elements into their simple type counterparts and updating the references between the XML elements accordingly.
I am unsure why this works, but it has solved my problem anyway.
If you had a complex attribute this is how you could do it
Before
<xs:element name="getMyMenu">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
After
<xs:complexType name="getMyMenu">
<xs:sequence>
<xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
And then change this
<wsdl:message name="getMyMenuRequest">
<wsdl:part name="parameters" type="ns0:getUssdMenu"/>
</wsdl:message>
To
<wsdl:message name="getMyMenuRequest">
<wsdl:part name="parameters" type="ns:getUssdMenu"/>
</wsdl:message>
That should be it! It did it for me....
This is just a hunch, but maybe you're having a namespace issue. If you focus on this part of the wsdl, notice that your parameter has an "ns0" namespace for the elements, but in your operations defined later, it looks like you're using an "axis2" namespace. With all of my Axis2 generated WSDLs, these two namespaces are the same.
<wsdl:message name="GetMessagesRequest">
<wsdl:part name="parameters" element="ns0:GetMessages"/>
</wsdl:message>
<wsdl:message name="GetMessagesResponse">
<wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<wsdl:message name="GetGroupsResponse">
<wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
</wsdl:message>
<wsdl:portType name="MyProjectPortType">
<wsdl:operation name="GetMessages">
<wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
<wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
<wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
</wsdl:operation>
</wsdl:portType>
Another thing you can check is to verify that the wsdl you got from java2wsdl is the same that is generated by axis2. Unless you have changed the default setting of "useoriginalwsdl" in your services.xml, these wsdls can "look" different. I never had to perform a java2wsdl manually to get my webservice to function correctly...
So basically, hit your service URL in a browser and tack on the ?wsdl at the end of the url...you should get a wsdl for comparison sake.
Also, have your client generate stubs from the server's wsdl instead of one that is generated by java2wsdl (assuming you originally used the wsdl from java2wsdl). Again, we never had to pass a manually generated wsdl around to anyone...they just simply consumed the dynamically generated one from the server...
Have you tried to send a request like this?
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<request>
<GetGroups xmlns="http://stws/xsd">
<serialcode>123456-654321</serialcode>
</GetGroups>
</request>
</soap:Body>
</soap:Envelope>
All my requests have the request tag before the actual request parameters.
try this:
123456-654321
Put xmlns="" into the parameter tag. I have the same problem and I don't know what I can modify in order to receive the parameter whitout the xmlnx.
I have another fix. I eventually discovered that if I didn't let my IDE (Netbeans 6.8) generate the WSDL then the web service worked. Alternatively if I deleted it, unticked the generate option and re-deployed then it worked.
Comparing a Netbeans generated WSDL to a server generated one I noticed the following differences :
xmlns:ns0="http:///xsd"
target namespace at the end of the wsdl:definitions tag had a trailing slash
ns0 used to choose the elements that make up the wsdl:message tag
Removing all these and re-deploying worked!