aspose file tools*
The moose likes Web Services and the fly likes client code to connect to Web services Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "client code to connect to Web services" Watch "client code to connect to Web services" New topic
Author

client code to connect to Web services

sam barker
Ranch Hand

Joined: Apr 26, 2008
Posts: 37
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
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
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

Joined: Apr 26, 2008
Posts: 37
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
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
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

Joined: Apr 26, 2008
Posts: 37
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

Joined: Aug 06, 2008
Posts: 25
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

Joined: Apr 26, 2008
Posts: 37
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

Joined: Apr 26, 2008
Posts: 37
Solved the problem.I should have been using the service locator to connect.
omar valenzuela
Greenhorn

Joined: Feb 15, 2011
Posts: 1
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: client code to connect to Web services