Consume Webservice in java

W

weetat

Hi all , I need to call method from webservice that I have created.
The webservice is deployed in jboss 4.0.4 and the webservice is simple
Hello test.

However , when i tried to call method , it gave error below:

I am new in webservice . Anyone have any ideas or suggestion is much
appreciated. Thanks


serialization error: serialization error:
java.lang.NullPointerException
at
com.sun.xml.rpc.encoding.DynamicInternalTypeMappingRegistry.getSerializer(DynamicInternalTypeMappingRegistry.java:
196)
at
com.sun.xml.rpc.encoding.literal.LiteralResponseSerializer.initialize(LiteralResponseSerializer.java:
230)
at
com.sun.xml.rpc.client.dii.BasicCall.createRpcLiteralResponseSerializer(BasicCall.java:
757)
at
com.sun.xml.rpc.client.dii.BasicCall.getResponseDeserializer(BasicCall.java:
690)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:
486)
at com.test.client.TestWebService.main(TestWebService.java:45)

This is the web service client code:

public static void main(String [] args){

try{

String wsdlURL = "http://cxrus020:8080/HelloWebService/
HelloWS?wsdl";
String namespace = "urn:HelloWS/wsdl";
String serviceName = "HelloWS";
QName serviceQN = new QName(namespace, serviceName);

ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service service = serviceFactory.createService(new
URL(wsdlURL), serviceQN);
Call call = service.createCall();
call.setPortTypeName(serviceQN);
call.setOperationName(new QName(namespace, "greet"));
call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");


call.addParameter("string_1",serviceQN,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(serviceQN);
Object[] inParams = new Object[]{"weetat is testing"};
String ret = (String) call.invoke(inParams);
System.out.println("ret:" + ret);

}catch(Exception ex){
ex.printStackTrace();
}


The wsdl file for your reference :

<definitions name='HelloWS' targetNamespace='urn:HelloWS/wsdl'
xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:soap='http://
schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='urn:HelloWS/wsdl'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<types></types>
<message name='HelloWSSEI_greet'>
<part name='String_1' type='xsd:string'/>
</message>
<message name='HelloWSSEI_greetResponse'>
<part name='result' type='xsd:string'/>
</message>
<portType name='HelloWSSEI'>
<operation name='greet' parameterOrder='String_1'>
<input message='tns:HelloWSSEI_greet'/>
<output message='tns:HelloWSSEI_greetResponse'/>
</operation>
</portType>
<binding name='HelloWSSEIBinding' type='tns:HelloWSSEI'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/
http'/>
<operation name='greet'>
<soap:eek:peration soapAction=''/>
<input>
<soap:body namespace='urn:HelloWS/wsdl' use='literal'/>
</input>
<output>
<soap:body namespace='urn:HelloWS/wsdl' use='literal'/>
</output>
</operation>
</binding>
<service name='HelloWS'>
<port binding='tns:HelloWSSEIBinding' name='HelloWSSEIPort'>
<soap:address location='http://cxrus020:8080/HelloWebService/
HelloWS'/>
</port>
</service>
</definitions>
 
B

Brandon McCombs

weetat said:
Hi all , I need to call method from webservice that I have created.
The webservice is deployed in jboss 4.0.4 and the webservice is simple
Hello test.

However , when i tried to call method , it gave error below:

I am new in webservice . Anyone have any ideas or suggestion is much
appreciated. Thanks


serialization error: serialization error:
java.lang.NullPointerException
at
com.sun.xml.rpc.encoding.DynamicInternalTypeMappingRegistry.getSerializer(DynamicInternalTypeMappingRegistry.java:
196)
at
com.sun.xml.rpc.encoding.literal.LiteralResponseSerializer.initialize(LiteralResponseSerializer.java:
230)
at
com.sun.xml.rpc.client.dii.BasicCall.createRpcLiteralResponseSerializer(BasicCall.java:
757)
at
com.sun.xml.rpc.client.dii.BasicCall.getResponseDeserializer(BasicCall.java:
690)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:
486)
at com.test.client.TestWebService.main(TestWebService.java:45)

This is the web service client code:
[snip]

Based on the error it doesn't have anything to do with web services
specifically. This is a basic null pointer exception that can occur
anywhere in Java. What are you doing on line 196 in the
DynamicInternalTypeMappingRegistry.java class? That's where the null
pointer is being referenced. If that isn't your class (since it's in a
package from sun) then you need to trace the source of the null pointer
into one of your classes.....such as line 45 in TestWebService.java.
 
M

Mike Schilling

weetat said:
Hi all , I need to call method from webservice that I have created.
The webservice is deployed in jboss 4.0.4 and the webservice is simple
Hello test.

However , when i tried to call method , it gave error below:

I am new in webservice . Anyone have any ideas or suggestion is much
appreciated. Thanks

A few things stand out:

1. The error appears to come while deserializing the response.
2. The following line looks odd to me:

call.setReturnType(serviceQN);

since serviceQN is neither a type nor the name of a type
3. The NPE appears to come while looking up a type in a registry of types.

Perhaps you want to call setReturnType(new
QName("'http://www.w3.org/2001/XMLSchema", "string"));
 
W

weetat

Hi,

Added , similar problem.
Please explain again , I am deploying a simple Hello Web service to
jboss-4.0.4-GA server with bundled in the Netbean 5.5 IDE.

Deployment of webservice in the JBoss is ok , when i do
http://localhost:8080/HelloWebService/HelloWS?wsdl , i can see the
wsdl format.
And when accessing the webservice using Web Service Client in
Netbean , i can access the web service method without any error.

My problem is the when i tried to access the web service in normal
java class for example below:
Anyone have any ideas or suggestion , please email it to me , thanx


import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;

public class TestWebService {


/** Creates a new instance of TestWebService */
public static void main(String [] args){

try{

String wsdlURL = "http://cxrus020:8080/HelloWebService/
HelloWS?wsdl";
String namespace = "urn:HelloWS/wsdl";
String serviceName = "HelloWS";
QName serviceQN = new QName(namespace, serviceName);

ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service service = serviceFactory.createService(new
URL(wsdlURL), serviceQN);
QName portQname = new QName(namespace, "HelloWSSEIPort");

Call call = service.createCall(portQname);
call.setPortTypeName(portQname);
call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
QName requestQname = new QName(namespace, "greet");
call.addParameter("String_1", requestQname,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(requestQname);
String ret = (String) call.invoke(new Object[]{"joshua
tat"});
System.out.println("ret:" + ret);


}catch(Exception ex){
ex.printStackTrace();
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top