+ Start a Discussion
RoopaRoopa 

How to invoke Webservice (WSDL created from APEX class) from java

Hi,
  In our application, the WSDL file has been created from Apex class.
I have created client stubs out of this WSDL. How can I invoke the Webservice from a
stand-alone java application?
Also, How can I download the Salesforce library files related to apex classes?
 
Thanks in advance.
 
 
SuperfellSuperfell
create an instance of the client stub.
set the session header (get a session from a webtab merge field or similar, or call login in the enterprise or partner apis)
call the method(s) on your stub.
CliffACliffA
Simon,
Would you please provide more detail around setting the session header using a session obtained via the partner API.  I too am trying to call an Apex Web Service from an application that's successfully calling Partner APIs.  So far I haven't had any success calling the Apex web services.

Thanks,
Cliff
SuperfellSuperfell
It'll depend on your toolkit, in .NET its as simple as

apexBinding.SessionHeader = new apex.SessionHeader();
apexBinding.SessionHeader.sessionId = loginResult.sessionId;

If you're using a tool like Axis 1.x where the headers are automatically mapped onto the stub for you, you'll need to make sure to get the SessionHeader namespace URI correct, check the WSDL, its different for every one.
CliffACliffA
Simon,
Thanks for the quick reply.  I'm using Java but at this point .NET sure looks appealing :smileywink:

Here's what I'm running right now (note that at this point in the code I have already successfully called a method on the Partner API).  PledgeUtils is my Apex class with the webservice methods exposed.

Code:
PledgeUtilsBindingStub pubs = new PledgeUtilsBindingStub();
String endpointProperty = PledgeUtilsBindingStub.ENDPOINT_ADDRESS_PROPERTY;
Object endpointAddress = m_partnerBinding._getProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY); // Get endpoint from binding to Partner API
pubs._setProperty(endpointProperty, endpointAddress);

com.cv.connector_sf.PledgeUtils.SessionHeader psh = new com.cv.connector_sf.PledgeUtils.SessionHeader(); 
psh.setSessionId(m_partnerSessionHeader.getSessionId()); // Set header with sessionID from Partner API binding

String nameSpace = new PledgeUtilsServiceLocator().getServiceName().getNamespaceURI();
pubs.setHeader(nameSpace, SESSION_HEADER, psh);

 When I call a method on the PledgeUtils I'm encountering the following exception:

Code:
AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
 faultSubcode: 
 faultString: No operation available for request {http://soap.sforce.com/schemas/class/cv/PledgeUtils}designationsComplete
 faultActor: 
 faultNode: 
 faultDetail: 
 {http://xml.apache.org/axis/}stackTrace:No operation available for request {http://soap.sforce.com/schemas/class/cv/PledgeUtils}designationsComplete
...

 
Any guidance you can provide would be greatly appreciated.

Thanks,
Cliff






Message Edited by CliffA on 08-21-2008 10:18 PM
SuperfellSuperfell
remove the code that's changing the endpoint property, and you'll be good to go.
CliffACliffA
Thanks for the super quick response.  I tried that and I get this:

Code:
AxisFault
 faultCode: {http://xml.apache.org/axis/}Server.NoEndpoint
 faultSubcode: 
 faultString: No endpoint
 faultActor: 
 faultNode: 
 faultDetail: 
...

 

SuperfellSuperfell
What url did wsdl2java bake into the PledgeUtilsBindingStub class ?
CliffACliffA
Ok, I think I got it.  I replaced the endpoint line

Code:
Object endpointAddress = m_partnerBinding._getProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY); // Get endpoint from binding to Partner API

with this line:
Code:
Object endpointAddress = new PledgeUtilsServiceLocator().getPledgeUtilsAddress();

 It's working now....

Thanks for setting me on the right course!

-Cliff
 

SuperfellSuperfell
Oh yeah, you should be creating an instance of the binding stub directly, you should be getting it from the ServiceLocator.
CliffACliffA
Ok, now it all makes sense.  For the record, here's the final solution based on your last post:

Code:
PledgeUtilsBindingStub pubs = (PledgeUtilsBindingStub) new PledgeUtilsServiceLocator().getPledgeUtils();

com.cv.connector_sf.PledgeUtils.SessionHeader psh = new com.cv.connector_sf.PledgeUtils.SessionHeader(); 
psh.setSessionId(m_sessionHeader.getSessionId()); // Set header to sessionID from Partner API binding

String nameSpace = new PledgeUtilsServiceLocator().getServiceName().getNamespaceURI();
pubs.setHeader(nameSpace, SESSION_HEADER, psh);

 Thanks again for your help - it was invaluable