accessing a java webservice from the webservice client - java

I am trying to access a java webservice by sending a soap request to the service
the strange part is that until recently it worked fine, and now it gives me an internal server error
what am i doing wrong ??
this is my soap message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://webservice.lenabru.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <q0:register><q0:regFirstName></q0:regFirstName><q0:regLastName></q0:regLastName><q0:regLoginName></q0:regLoginName><q0:regPassword></q0:regPassword><q0:regAddress></q0:regAddress><q0:regEmail></q0:regEmail><q0:regPhone></q0:regPhone></q0:register></soapenv:Body></soapenv:Envelope>
and this is the response i get from the server
"<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>java.lang.reflect.InvocationTargetException</faultstring>
<detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">Lena</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>"
this is the contents of the webmethod i am trying to reach:
#WebMethod
public boolean register(String regFirstName, String regLastName, String regLoginName, String regPassword, String regAddress, String regPhone, String regEmail) {
return false;
}
this is my wsdl:
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.lenabru.com" xmlns:intf="http://webservice.lenabru.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://webservice.lenabru.com">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://webservice.lenabru.com">
<element name="register">
<complexType>
<sequence>
<element name="regFirstName" type="xsd:string"/>
<element name="regLastName" type="xsd:string"/>
<element name="regLoginName" type="xsd:string"/>
<element name="regPassword" type="xsd:string"/>
<element name="regAddress" type="xsd:string"/>
<element name="regPhone" type="xsd:string"/>
<element name="regEmail" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="registerResponse">
<complexType>
<sequence>
<element name="registerReturn" type="xsd:boolean"/>
</sequence>
</complexType>
</element>
<element name="isUserExists">
<complexType>
<sequence>
<element name="userName" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="isUserExistsResponse">
<complexType>
<sequence>
<element name="isUserExistsReturn" type="xsd:boolean"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="isUserExistsResponse">
<wsdl:part element="impl:isUserExistsResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="registerRequest">
<wsdl:part element="impl:register" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="isUserExistsRequest">
<wsdl:part element="impl:isUserExists" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="registerResponse">
<wsdl:part element="impl:registerResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="ElectronicArenaWebService">
<wsdl:operation name="register">
<wsdl:input message="impl:registerRequest" name="registerRequest"></wsdl:input>
<wsdl:output message="impl:registerResponse" name="registerResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="isUserExists">
<wsdl:input message="impl:isUserExistsRequest" name="isUserExistsRequest"></wsdl:input>
<wsdl:output message="impl:isUserExistsResponse" name="isUserExistsResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ElectronicArenaWebServiceSoapBinding" type="impl:ElectronicArenaWebService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="register">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="registerRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="registerResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="isUserExists">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="isUserExistsRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="isUserExistsResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ElectronicArenaWebServiceService">
<wsdl:port binding="impl:ElectronicArenaWebServiceSoapBinding" name="ElectronicArenaWebService">
<wsdlsoap:address location="http://localhost:8080/ElectronicArenaLena/services/ElectronicArenaWebService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

First a note: if you're using Tomcat 7 (why not use Axis 2 ?)
Setup for Log4j (at the time axis 1 was still there there was log4j, now there is a better alternatives from the same author of Log4j it's called logback - however there is a new Log4j 2 now but I haven't tested it for this setup only the one that comes with axis downloaded here
http://archive.apache.org/dist/ws/axis/1_4/)
create a log4j.properties file and put it in your WEB-INF/classes folder
(I created a sample content so that you can get going, might need to look at log4j's documentation to modify the logs as you need - the below creates multiple log files(max 5) whenever one's size reaches 100k it creates another, you might need to change the size or number as needed or just use one)
log4j.rootLogger=DEBUG, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.File=axis.log
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} – %m%n
# below line might not be needed, but I just had it there
log4j.R.org.apache.axis=DEBUG
now open axis.jar and remove whatever properties file you have directly in the folder structure (next to MANIFEST and org folders - I had simplelog.properties so I deleted it)
restart apache tomcat and check the apache logs to make sure log4j isn't throwing any warnings or errors
If everything works fine, you should be able to see axis.log in apache tomcat's bin directory
Note:
you might notice a lot of useless debug logs, however when an exception occurs or some issue happens it might be handy to have this level of details in your logs, plus you can disable it anytime you need, just replace rootLogger DEBUG into INFO or comment log4j.properties all together
References:
http://osdir.com/ml/text.xml.axis.user/2002-08/msg00436.html
http://axis.apache.org/axis/java/developers-guide.html#LoggingTracing

Related

How to fix wsdl file errors?

Dears
I trying to make and create web service, firstly i created the server side and wsdl file, but i get some errors in this wsdl file and i tried many time to solve it, i guess i should check the xmlns or xsd.
actually i'am new in webwervices and don't now exactly how to investigate them, please advise me and let me know the error in my code.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://DefaultNamespace"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://DefaultNamespace"
xmlns:intf="http://DefaultNamespace"
xmlns:tns1="http://swing.javax"
xmlns:tns2="http://awt.java"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified"
targetNamespace="http://DefaultNamespace"
xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://awt.java"/>
<import namespace="http://swing.javax"/>
The errors is
Description Resource Path Location Type
src-resolve: Cannot resolve the name 'tns1:JPasswordField' to a(n) 'type definition' component. ImbCal.wsdl /SSPtest/WebContent/wsdl line 196 WSDL Problem
Description Resource Path Location Type
src-resolve: Cannot resolve the name 'tns2:List' to a(n) 'type definition' component. ImbCal.wsdl /SSPtest/WebContent/wsdl line 171 WSDL Problem
Description Resource Path Location Type
schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not . ImbCal.wsdl /SSPtest/WebContent/wsdl line 7 WSDL Problem
Description Resource Path Location Type
schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not . ImbCal.wsdl /SSPtest/WebContent/wsdl line 8 WSDL Problem
here one of elements
<element name="dbSelect">
<complexType>
<sequence>
<element name="sql" type="xsd:string"/>
<element name="level" type="xsd:string"/>
<element name="mat_sel2" type="tns2:List"/>
<element name="mymaterial" type="tns2:List"/>
</sequence>
</complexType>
</element>
This is the full code, i just edit the wrong from the code and regenerate the wsdll.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://DefaultNamespace"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://DefaultNamespace"
xmlns:intf="http://DefaultNamespace"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified"
targetNamespace="http://DefaultNamespace" xmlns="http://www.w3.org
/2001/XMLSchema">
<element name="main">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="arg" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="mainResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="mainReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="finalmaterial">
<complexType>
<sequence>
<element name="Couresn" type="xsd:string"/>
<element name="IDL" type="xsd:string"/>
<element name="Myco2" type="xsd:string"/>
<element name="userlevel" type="xsd:int"/>
<element name="LevelL" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="finalmaterialResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="finalmaterialReturn"
type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="finalmaterialRequest">
<wsdl:part element="impl:finalmaterial" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="finalmaterialResponse">
<wsdl:part element="impl:finalmaterialResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="mainRequest">
<wsdl:part element="impl:main" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="mainResponse">
<wsdl:part element="impl:mainResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="ImbCal">
<wsdl:operation name="main">
<wsdl:input message="impl:mainRequest" name="mainRequest">
</wsdl:input>
<wsdl:output message="impl:mainResponse" name="mainResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="finalmaterial">
<wsdl:input message="impl:finalmaterialRequest"
name="finalmaterialRequest">
</wsdl:input>
<wsdl:output message="impl:finalmaterialResponse"
name="finalmaterialResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ImbCalSoapBinding" type="impl:ImbCal">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="main">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="mainRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="mainResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="finalmaterial">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="finalmaterialRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="finalmaterialResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ImbCalService">
<wsdl:port binding="impl:ImbCalSoapBinding" name="ImbCal">
<wsdlsoap:address location="http://localhost:8080/SSPwebservice
/services/ImbCal"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

How to Return an Class with an Array in Java webservices Consumed by C#

I am having trouble creating a java webservice that returns an Array inside a class. I created a java websrevice with a class and inside the class I created a new Array that will return another Class. But when Importing the WSDL in a C# project I cant access the Array inside the class.
My java web service example :
My industry class :
public class Industry {
public int industryID;
public String industryName;
public Product[ ] products;
}
The Idea is to return the industry with all the products of the industry.
The Product Class :
public class Product {
public int productID;
public String productName;
}
My webservice that populates the industry and the Products for the Industry. Please nte I know I am suposed to create get and set methods to set the values.. I only created a small examle of my problem.
My Webservice class :
public class IndustryService {
/**
* #param industryID
* #return industry object
*/
public Industry getIndustryData(int industryID){
Product product1 = new Product();
product1.productID = 712;
product1.productName = "Sensor Light";
Product product2 = new Product();
product2.productID = 1774;
product2.productName = "Light Beamer";
Product [] products = new Product[] { product1, product2 };
Industry industry = new Industry();
industry.industryID = 2311;
industry.industryName = "Test";
industry.products = products;
return industry;
}
}
Here's the WSDL that gets generated in java :
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://server.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://server.com" xmlns:intf="http://server.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://server.com" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="getIndustryData">
<complexType>
<sequence>
<element name="industryID" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="getIndustryDataResponse">
<complexType>
<sequence>
<element name="getIndustryDataReturn" type="impl:Industry"/>
</sequence>
</complexType>
</element>
<complexType name="Product">
<sequence>
<element name="productID" type="xsd:int"/>
<element name="productName" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="ArrayOfProduct">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="impl:Product"/>
</sequence>
</complexType>
<complexType name="Industry">
<sequence>
<element name="industryID" type="xsd:int"/>
<element name="industryName" nillable="true" type="xsd:string"/>
<element name="products" nillable="true" type="impl:ArrayOfProduct"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getIndustryDataResponse">
<wsdl:part element="impl:getIndustryDataResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getIndustryDataRequest">
<wsdl:part element="impl:getIndustryData" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IndustryService">
<wsdl:operation name="getIndustryData">
<wsdl:input message="impl:getIndustryDataRequest" name="getIndustryDataRequest">
</wsdl:input>
<wsdl:output message="impl:getIndustryDataResponse" name="getIndustryDataResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="IndustryServiceSoapBinding" type="impl:IndustryService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getIndustryData">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getIndustryDataRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getIndustryDataResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="IndustryServiceService">
<wsdl:port binding="impl:IndustryServiceSoapBinding" name="IndustryService">
<wsdlsoap:address location="http://localhost:8080//IIIII/services/IndustryService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Now when consuming it using c# I expect to get a Industry Containing 2 products but C# shows that theres 0 inside of product array...
C# example created a normal form and imported the java WSDL as service reference:
private void Form1_Load(object sender, EventArgs e)
{
ServiceReference1.IndustryServiceClient client = new WindowsFormsApplication4.ServiceReference1.IndustryServiceClient();
ServiceReference1.Industry m = client.getIndustryData(2);
string a = "test";
}
When I debug windows form I get the following :
Notice the Product Array count is 0?
Why is this zero and What am I doing wrong?
Is the problem in the java side or c# side?
I am using eclipse to create the java webservice and Visual studio to import wsdl.
In soap UI I also imported the WSDL just to test the webservice to see the request and response and It looks correct :
Request :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://server.com">
<soapenv:Header/>
<soapenv:Body>
<ser:getIndustryData>
<ser:industryID>2</ser:industryID>
</ser:getIndustryData>
</soapenv:Body>
</soapenv:Envelope>
Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getIndustryDataResponse xmlns="http://server.com">
<getIndustryDataReturn>
<industryID>2311</industryID>
<industryName>Test</industryName>
<products>
<productID>712</productID>
<productName>Sensor Light</productName>
</products>
<products>
<productID>1774</productID>
<productName>Light Beamer</productName>
</products>
</getIndustryDataReturn>
</getIndustryDataResponse>
</soapenv:Body>
</soapenv:Envelope>
Code in the reference.cs file I edited :
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="products", Namespace="http://server.com", ItemName="item")]
[System.SerializableAttribute()]
public class ArrayOfProduct : System.Collections.Generic.List<WindowsFormsApplication4.ServiceReference1.Product> {
}
In the Reference.cs file I changed the Name and ItemName tag to Products and now it is working.
[System.Runtime.Serialization.CollectionDataContractAttribute(Name = "products", Namespace = "http://server.com", ItemName = "products")]
Visual Studio creates the stub and expects the elements of products with the tag name "ArrayOfProduct" but the server sends them with the following tag
<products>
See the reference.cs file under the service reference (you need to check the Show All Files for the project).
It is not a good practice, but to resolve the issue, you can manipulate the reference.cs file manually to change the CollectionDataContractAttribute to "products" on top of the definition of public class ArrayOfProduct

Can't get an output while calling java web service using php

I have create a web service using java. I used the below code to call the web service using php.
$client = new SoapClient("http://localhost:8080/imageCom/wsdl/CompareImage.wsdl");
$stock = "http://localhost/pic/blueTshirts/b10.jpg";
$parameters= array("url"=>$stock);
$values = $client->checkSimilarity($parameters);
var_dump($values);
When I run the code I get the following output. But it doesn't display the result
output: object(stdClass)#2 (0) { }
Here is my WSDL
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://simalarity.imageCom" xmlns:intf="http://simalarity.imageCom" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://simalarity.imageCom">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://simalarity.imageCom">
<element name="checkSimilarity">
<complexType>
<sequence>
<element name="url" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="checkSimilarityResponse">
<complexType/>
</element>
</schema>
</wsdl:types>
<wsdl:message name="checkSimilarityRequest">
<wsdl:part element="impl:checkSimilarity" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="checkSimilarityResponse">
<wsdl:part element="impl:checkSimilarityResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="CompareImage">
<wsdl:operation name="checkSimilarity">
<wsdl:input message="impl:checkSimilarityRequest" name="checkSimilarityRequest"></wsdl:input>
<wsdl:output message="impl:checkSimilarityResponse" name="checkSimilarityResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CompareImageSoapBinding" type="impl:CompareImage">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="checkSimilarity">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="checkSimilarityRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="checkSimilarityResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CompareImageService">
<wsdl:port binding="impl:CompareImageSoapBinding" name="CompareImage">
<wsdlsoap:address location="http://localhost:8080/imageCom/services/CompareImage"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
What I am doing wrong? Please help me.
The thing is you are getting standard class object array in return.
You have to extract the values accordingly
print_r($array) will print your array recursively.
You may also loop over an array of objects like below,
foreach ($array as $key => $object) {
echo $object->object_property;
}
Think of an array as a collection of things. It's a bag where you can store your stuff and give them a unique id (key) and access them.

Why does wsimport add #XmlSchemaType(name = "string")?

This is happening when I use a more recent version of wsimport. The example WSDL below contains a SimpleType "SomeEnum" that becomes an enum in the JAXB class. I have some code that generates the XSD schema back from the JAXB class and previously it would correctly assign the type tns:SomeEnum to this element but now treats it as string.
I eventually discovered that wsimport was adding the annotation #XmlSchemaType(name = "string"), causing this behavior. This seems wrong to me, because there is a more specific type than string. It is also breaking code that depends on back-generating the schema.
Here is the smallest WSDL I could come up with to reproduce the error.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
targetNamespace="http://foo.bar.com/example"
xmlns:tns="http://foo.bar.com/example"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema elementFormDefault="qualified" jaxb:version="1.0"
targetNamespace="http://foo.bar.com/example"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:tns="http://foo.bar.com/example">
<annotation>
<appinfo>
<jaxb:globalBindings typesafeEnumMaxMembers="999999"/>
</appinfo>
</annotation>
<complexType name="Wrapper">
<sequence>
<element maxOccurs="1" minOccurs="0" name="someEnum" type="tns:SomeEnum"/>
</sequence>
</complexType>
<simpleType name="SomeEnum">
<restriction base="xsd:string">
<enumeration value="SOME_VALUE"/>
<enumeration value="ANOTHER_VALUE"/>
</restriction>
</simpleType>
<element name="doesNothing">
<complexType>
<sequence>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="doesNothingRequest">
<wsdl:part element="tns:doesNothing" name="parameters"/>
</wsdl:message>
<wsdl:portType name="SimpleTypeIssueServiceInterface">
<wsdl:operation name="doesNothing">
<wsdl:input message="tns:doesNothingRequest" name="doesNothingRequest"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SimpleTypeIssueServiceSoapBinding" type="tns:SimpleTypeIssueServiceInterface">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="doesNothing">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="doesNothingRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SimpleTypeIssueService">
<wsdl:port binding="tns:SimpleTypeIssueServiceSoapBinding" name="SimpleTypeIssueServiceInterfacePort">
<wsdlsoap:address location="LOCATION_TEMPLATE"/>
</wsdl:port>
</wsdl:service>
And here is a fragment of the generated Wrapper.java. The #XmlSchemaType annotation is missing in Java7 wsimport (which I want) and present in Java8 wsimport. I don't know if this is fixing a bug or introducing one.
...
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "Wrapper", propOrder = {
"someEnum"
})
public class Wrapper {
#XmlSchemaType(name = "string") // [Why is this added?]
protected SomeEnum someEnum;
/**
* Gets the value of the someEnum property.
*
* #return
* possible object is
* {#link SomeEnum }
*
*/
public SomeEnum getSomeEnum() {
return someEnum;
}
...
}
#XmlSchemaType(name = "string") protected SomeEnum someEnum; this means xsd type of this java property is xsd:string (base="xsd:string"). Look at A JAXB Nuance: String Versus Enum from Enumerated Restricted XSD String this for detailed explanation.

Calling Axis Web Service with Complex Data Type

I have the following wsdl:
<wsdl:definitions targetNamespace="http://localhost:8080/webservice/Retriever.jws">
<wsdl:types>
<schema targetNamespace="http://localhost:8080/webservice/Retriever.jws">
<import namespace="http://DefaultNamespace"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ArrayOf_xsd_string">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
</restriction>
</complexContent>
</complexType>
<complexType name="ArrayOf_xsd_int">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:int[]"/>
</restriction>
</complexContent>
</complexType>
</schema>
<schema targetNamespace="http://DefaultNamespace">
<import namespace="http://localhost:8080/webservice/Retriever.jws"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="Result">
<sequence>
<element name="time" type="xsd:int"/>
<element name="title" nillable="true" type="impl:ArrayOf_xsd_string"/>
<element name="url" nillable="true" type="impl:ArrayOf_xsd_string"/>
<element name="snippet" nillable="true" type="impl:ArrayOf_xsd_string"/>
<element name="position" nillable="true" type="impl:ArrayOf_xsd_int"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="retrieveResponse">
<wsdl:part name="retrieveReturn" type="tns1:Result"/>
</wsdl:message>
<wsdl:message name="retrieveRequest">
<wsdl:part name="query" type="xsd:string"/>
<wsdl:part name="n" type="xsd:int"/>
<wsdl:part name="start" type="xsd:int"/>
</wsdl:message>
<wsdl:portType name="Retriever">
<wsdl:operation name="retrieve" parameterOrder="query n start">
<wsdl:input message="impl:retrieveRequest" name="retrieveRequest"/>
<wsdl:output message="impl:retrieveResponse" name="retrieveResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="RetrieverSoapBinding" type="impl:Retriever">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="retrieve">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="retrieveRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded"/>
</wsdl:input>
<wsdl:output name="retrieveResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/webservice/Retriever.jws" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RetrieverService">
<wsdl:port binding="impl:RetrieverSoapBinding" name="Retriever">
<wsdlsoap:address location="http://localhost:8080/webservice/Retriever.jws"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
How may I call it!?

Categories