Conflict between 2 .xsd files of the same SOAP Service - web-services

I have a webservice, and I'm trying to write a client for it. But when I try to add a "Web Service Client" in Netbeans IDE, wsimport utility cannot parse the .wsdl. The reason is "The class serviceCompany is already in use".
I began to analyze the wsdl file, and noticed that there are 2 .xsd files related to the WS.
<types>
<xsd:schema>
<xsd:import namespace="http://services.ws.x.net/" schemaLocation="https://test.x:443/PaymentWS/PaymentWS?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://commonws.ws.x.net/" schemaLocation="https://test.x:443/PaymentWS/PaymentWS?xsd=2"/>
</xsd:schema>
</types>
And I have a complex type named "ServiceCompany" inside of each .xsd files.
inside ?xsd=1:
<xs:complexType name="serviceCompany">
<xs:sequence>
<xs:element name="bankAccount" type="tns:iban"/>
<xs:element name="code" type="tns:companyCode"/>
<xs:element name="description" type="tns:stringMax32"/>
<xs:element name="taxNumber" type="tns:taxNumber"/>
</xs:sequence>
</xs:complexType>
inside ?xsd=2:
<xs:complexType name="serviceCompany">
<xs:sequence>
<xs:element name="code" type="cmn:companyCode"/>
<xs:element name="description" type="cmn:stringMax32"/>
<xs:element name="manualPaymentReceiverCode" type="cmn:companyCode" minOccurs="0"/>
<xs:element name="scCategoryList" type="cmn:stringMax32" maxOccurs="unbounded"/>
<xs:element name="status" type="cmn:objectStatus"/>
<xs:element name="branchList" type="tns:serviceCompanyBranch" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
The namespaces of there .xsd files are different, why wsimport cannot import the wsdl? How can I solve this problem?
Thanks in advance!

Related

Generate wsdl from xsd using common property from common xsd file

I have to generate separate wsdl for separate client.
entry.xsd -> entry.wsdl
migration.xsd -> migration.wsdl
I am using spring boot contract frist approach for generating wsdl from xsd definition. Problem is type are same for both xsd fiels like: credential, so I want to create a common xsd file and include/import in both xsd so can reduce redundant code.
like common.xsd -> entry.xsd, migration.xsd
but getting exception or soap client giving invalid error message.
Any help, how to generate wsdl from two xsd where one is base xsd file?
It's giving, failed to update interface. InvalidFormatException from SOAP Client.
entry.sxd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.test.com/idms-ws"
targetNamespace="http://www.test.com/idms-ws"
elementFormDefault="qualified">
<xs:include schemaLocation="common-element.xsd"></xs:include>
<xs:element name="updateMigrationStatusRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="credential" type="tns:credential" minOccurs="0"/>
<xs:element name="referenceNo" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
common-element.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="credential">
<xs:sequence>
<xs:element name="loginName" type="xs:string" minOccurs="0"/>
<xs:element name="password" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Parse soap msg with gSOAP

I have following example xml message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<to>...</to>
<from>...</from>
<id>..</id>
<relatesTo>...</relatesTo>
<action>...</action>
<version>...</version>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<customComplexElement>
<a>a_v</a>
<b>b_v</b>
<c>c_v</c>
<d>d_v</d>
<e>e_v</e>
<f>f_v</f>
</customComplexElement>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
From which I have generated a xsd file with use of one of online tools:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="id" type="xs:string"/>
<xs:element name="relatesTo" type="xs:string"/>
<xs:element name="action" type="xs:string"/>
<xs:element name="version" type="xs:string"/>
<xs:element name="customComplexElement">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="a"/>
<xs:element type="xs:string" name="b"/>
<xs:element type="xs:string" name="c"/>
<xs:element type="xs:string" name="d"/>
<xs:element type="xs:string" name="e"/>
<xs:element type="xs:string" name="f"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then I generate the appropriate header file with wsdl2h.exe and then compile it with soapcpp2.exe compiler.
Then I try to read xml file with a function soap_read_customComplexElement() and all I get is SOAP_TAG_MISMATCH. This method seems to work if I get rid of all the soap stuff the message but I wonder if there are some functions in gSOAP to parse soap envelope, header and body?
I've had same problem. But i've just fixed it.
So, in my case i use this line of code.
struct soap *soap = soap_new1(SOAP_C_UTFSTRING | SOAP_XML_IGNORENS | SOAP_XML_TREE);
The key paramter is SOAP_XML_IGNORENS. This parameter ignore namespaces.
SOAP_XML_IGNORENS in: ignores the use of XML namespaces in input
The root of this problem is that you don't declare namespaces in your body content. That why gSoap don't know how to convert this xml.
This wouldn't be converted, because gSoap don't know what is ns4:
<ns4:ParseKeywords><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords>
But if i declare namespace it will be converted
<ns4:ParseKeywords xmlns:ns4="com.idurdyev.idcommerce:ParseKeywords:1.0"><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords>

SOAP server reads web method parameters as null

I have a client that connects to a SOAP server endpoint:
Endpoint.publish("http://localhost:8081/todo", new ToDoWebService());
The server offers the next simple method:
#WebService
public class ToDoWebService {
#WebMethod()
public String addToDo(String task, String context, String project, int priority) {
return "ToDo: \n "
+ "\t Task : "+task+"\n"
+ "\t Context : "+context+"\n"
+ "\t Project : "+project+"\n"
+ "\t Priority: "+priority;
}
}
This is the client:
public class Client {
public static void main(String[] args) {
ToDoWebServiceService tdwss = new ToDoWebServiceService();
ToDoWebService tdws = tdwss.getToDoWebServicePort();
System.out.println(tdws.addToDo("Task 1","My Context","My Project",9));
}
}
The thing is that the connection between client and server is succesful, but not entirely: the pass of the arguments from the client to the service is not made as expected, been this the result on the client once executed:
The server doesn't receive correctly the arguments that the client has passed with the method "addToDo()" call. It returns the string format expected but with nulls instead the arguments passed by the client. And that's what I can't figure out...
Of course, I'm pretty confident the WSDL file is well written:
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.8 svn-revision#13980. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.8 svn-revision#13980. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://todows.bigws/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://todows.bigws/" name="ToDoWebServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://todows.bigws/" schemaLocation="toDo.xsd"/>
</xsd:schema>
</types>
<message name="addToDo">
<part name="parameters" element="tns:addToDo"/>
</message>
<message name="addToDoResponse">
<part name="parameters" element="tns:addToDoResponse"/>
</message>
<portType name="ToDoWebService">
<operation name="addToDo">
<input wsam:Action="http://todows.bigws/ToDoWebService/addToDo" message="tns:addToDo"/>
<output wsam:Action="http://todows.bigws/ToDoWebService/addToDoResponse" message="tns:addToDoResponse"/>
</operation>
</portType>
<binding name="ToDoWebServicePortBinding" type="tns:ToDoWebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="addToDo">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ToDoWebServiceService">
<port name="ToDoWebServicePort" binding="tns:ToDoWebServicePortBinding">
<soap:address location="http://localhost:8081/todo"/>
</port>
</service>
</definitions>
As well as the schema "toDo.xsd":
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.8 svn-revision#13980. -->
<xs:schema xmlns:tns="http://todows.bigws/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://todows.bigws/">
<xs:element name="addToDo" type="tns:addToDo"/>
<xs:element name="addToDoResponse" type="tns:addToDoResponse"/>
<xs:complexType name="addToDo">
<xs:sequence>
<xs:element name="task" type="xs:string" minOccurs="0"/>
<xs:element name="context" type="xs:string" minOccurs="0"/>
<xs:element name="project" type="xs:string" minOccurs="0"/>
<xs:element name="priority" type="xs:int" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addToDoResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
I've tried different actions in the server method, as writing the string with the parameter in a file, but the result is the same, an error cause the parameters are null. That's what I think proves that the failure is located in the way the server receive the parameters passed to the "addToDo()" method.
I've review the WSDL & schema files over and over....but I've not been able to find what make this code run wrongly. I've also tested this code with the SoapUI software and the outcome is the same.
¿Any ideas?
P.D.: Sorry about all the posted code.
In case you need the whole project: my SOAP project at GitHub
I reviewed your WSDL and XSD in your project todows-cli-ws and the problem is the WSDL and XSD files in your client project are outdated!
For example, this is the current content of the XSD file of your server.
<xs:schema xmlns:tns="http://todows.bigws/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0" targetNamespace="http://todows.bigws/">
<xs:element name="addToDo" type="tns:addToDo"/>
<xs:element name="addToDoResponse" type="tns:addToDoResponse"/>
<xs:element name="listToDo" type="tns:listToDo"/>
<xs:element name="listToDoResponse" type="tns:listToDoResponse"/>
<xs:element name="removeToDo" type="tns:removeToDo"/>
<xs:element name="removeToDoResponse" type="tns:removeToDoResponse"/>
<xs:complexType name="addToDo">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
<xs:element name="arg1" type="xs:string" minOccurs="0"/>
<xs:element name="arg2" type="xs:string" minOccurs="0"/>
<xs:element name="arg3" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addToDoResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="removeToDo">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="removeToDoResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="listToDo">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="listToDoResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Note that the current name of the params are arg0, arg1, arg2 and arg3. The server expects as param names task, context, project and priority, and therefore the method is invoked with the default values (null for a String and 0 for an int).

Primary and foreign keys in xml schema

I am trying to insert primary and foreign keys in XSD schema file below :-
Primary key is StudentID and Foreign Keys are courseID, AddressID, GradeID.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Student">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Dateborn" type="xs:date"/>
<xs:element name="Gender" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
However above code is not working in my setup please help me in tracing the issue,
In general you would need to put more details in a question... So this should be enough to understand what else you might need to define, and how. I'll tackle what's needed to understand how to define a primary key/foreign key by illustrating an assumed student/address relationship.
First you need to define a context where these constraints hold true. In my modified XSD, I call it the "World".
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="World">
<xs:complexType>
<xs:sequence>
<xs:element ref="Student" maxOccurs="unbounded"/>
<xs:element ref="Address" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:key name="PKStudents">
<xs:selector xpath="Student/StudentID"/>
<xs:field xpath="."/>
</xs:key>
<xs:key name="PKAddresses">
<xs:selector xpath="Address/AddressID"/>
<xs:field xpath="."/>
</xs:key>
<xs:keyref name="FKStudentToAddress" refer="PKAddresses">
<xs:selector xpath="Student/AddressID"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>
<xs:element name="Student">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Dateborn" type="xs:date"/>
<xs:element name="Gender" type="xs:string"/>
<xs:element name="StudentID" type="xs:string"/>
<xs:element name="AddressID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="AddressID" type="xs:string"/>
<xs:element name="Street" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="Province" type="xs:string" minOccurs="0"/>
<xs:element name="Country" type="xs:date" minOccurs="0"/>
<xs:element name="PostalCode" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then an XML like this would pass or fail, depending on what you do with the values in the StudentID and AddressID fields.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<World xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Student>
<Title>Title1</Title>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Dateborn>1900-01-01</Dateborn>
<Gender>Gender1</Gender>
<StudentID>StudentID1</StudentID>
<AddressID>AddressID1</AddressID>
</Student>
<Student>
<Title>Title1</Title>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Dateborn>1900-01-01</Dateborn>
<Gender>Gender1</Gender>
<StudentID>StudentID2</StudentID>
<AddressID>AddressID1</AddressID>
</Student>
<Address>
<AddressID>AddressID1</AddressID>
<Street>Street1</Street>
<City>City1</City>
<Province>Province1</Province>
<Country>1900-01-01</Country>
<PostalCode>PostalCode1</PostalCode>
</Address>
<Address>
<AddressID>AddressID2</AddressID>
<Street>Street1</Street>
<City>City1</City>
<Province>Province1</Province>
<Country>1900-01-01</Country>
<PostalCode>PostalCode1</PostalCode>
</Address>
</World>
To finish your solution, you would need to define the Course and Grade "entities" in your "world", define the xs:key for each, similar to Student/*Address*, then add CourseID and GradeID attributes to the entities that need them, and finally, define the keyref, as above, for Entity to Grade and Entity to Course.

Removing WSDL differences while migrating from Axis2 to CXF

I am migrating my webservice publishing API from AXIS2 to CXF. CXF autogenerated WSDL is not similar to Axis2 WSDL. There are given below differences. As client sits somewhere else I am not able to test if these differences will affect Axis2 generated clients. How can remove these WSDL differences using CXF?
CXF WSDL
<xs:element name="test" type="tns:test"/>
<xs:element name="testResponse" type="tns:testResponse"/>
<xs:complexType name="test">
<xs:sequence> <xs:element name="doc" type="xs:string" minOccurs="0"/> </xs:sequence>
</xs:complexType>
<xs:complexType name="testResponse">
<xs:sequence> <xs:element name="return" type="xs:string" minOccurs="0"/> </xs:sequence>
</xs:complexType>
<wsdl:portType name="TESTService">
Axis2 WSDL
<xsd:element name="test" nillable="true" type="xsd:string" />
<xsd:element name="testResponse" nillable="true" type="xsd:string" />
<wsdl:portType name="TEST">
Most likely, adding an annotation of:
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
would do it. You may also need to update "name" attributes of the #WebParam and #WebReturn params.
To get rif of xs:elemntName difference, remove '#WebParams' from web service input as it is accepting just a String not any complex object.
To remove wsdl:portType name difference, just added '#WebService(name) attribute. '#WebService' should be as per the specification order else cxf won't consider them in WSDL.