Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

client code to connect to Web services

 
sam barker
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to develop a web service(my first) using the top down approach.
I was able to develop,validate and deploy the service.
How do I create a client the working of the service.

I know that at first you get an instance of the service locator..ie
MyWSDLFile_ServiceLocator test=new MyWSDLFile_ServiceLocator();

But after that I couldnt get the stub of the service as ServiceLocator does not have the appropriate get.... function..I hope I am clear.

Cheers,
Sam
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the service is up and running, then the SOAP server generally publish its WSDL (often at the URL of the service with an appended "?WSDL").

Armed with the WSDL, you should be able to create client-side code by using a tool of whatever SOAP toolkit you're using; it might be called "wsdl2java" or something. That will create all the Java classes necessary to access the service.
 
sam barker
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad ....you are correct.I ran that,then wrote a client.it looks like something like this...

MyWSDLFileSOAPStub x= new MyWSDLFileSOAPStub();
String z=x.myFirst("ho", "srte");//garbage arguments
System.out.println(z);



But when I run this I am getting an exception.....


Exception in thread "main" AxisFault
faultCode: {http://xml.apache.org/axis/}Server.NoEndpoint
faultSubcode:
faultString: No endpoint
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}exceptionName rg.apache.axis.NoEndPointException
{http://xml.apache.org/axis/}stackTrace:No endpoint
at org.example.www.MyFirstWSDL.MyFirstWSDLSOAPStub.myFirst(MyFirstWSDLSOAPStub.java:94)
at MyFirstClient.main(MyFirstClient.java:10)
at org.example.www.MyFirstWSDL.MyFirstWSDLFileSOAPStub.myFirst(MyFirstWSDLSOAPStub.java:94)

=========================================================================
The exception is thrown because super.cacheendpoint is null

public java.lang.String myFirst(java.lang.String time, java.lang.String loc) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[0]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI("http://www.example.org/MyFirstWSDLFile/MyFirst");
_call.setEncodingStyle(null);
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName("http://www.example.org/MyFirstWSDLFile/", "MyFirst"));

setRequestHeaders(_call);
setAttachments(_call);
try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {time, loc});

if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
try {
return (java.lang.String) _resp;
} catch (java.lang.Exception _exception) {
return (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String.class);
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
throw axisFaultException;
}

Cheers,
Sma
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to make sure, you did replace the two example.org URLs with the URLs of your web service, right?
[ August 15, 2008: Message edited by: Ulf Dittmer ]
 
sam barker
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No but I have changed it now.
I changed the SOAP:address in my WSDL file

<soap:address location="http://localhost:8080/axis/services/MyFirstWSDLFileSOAP"/>

But after compiling the server and client code I am still getting the same error..
 
Shawn Montague
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you are getting the same error after you regenerate the WSDL code? You will need to do that as well, not just a recompile.
 
sam barker
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I had regenerated the client and server side.
But the SOAP operation is still
wsdlsoap peration soapAction="http://www.example.org/MyFirstWSDLFile/MyFirst"/>

Is that alright
 
sam barker
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved the problem.I should have been using the service locator to connect.
 
omar valenzuela
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam barker wrote:Solved the problem.I should have been using the service locator to connect.


hi do you have the code of your solution?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic