You need to sign in to do that
Don't have an account?
Example of weservice
Hi Guys,
I have to demo an example of webservice to clients.
Can you guys provide me with an working example(End-to- end)
even the simplest example will do
like a method which calculates sum of two number or whatever.
It' Urgent
Regards,
16
Hi,
Try the below code snippet as reference:
WSDL Example
write Apex Code to add two numbers in orgA, Like
global class WebSrvceAddNumbers {
webService static integer AddNum(Integer a,Integer b)
{
integer sum=a+b;
return sum;
}
testMethod static void testWebSrvceAddNumbers()
{
WebSrvceAddNumbers w= new WebSrvceAddNumbers();
WebSrvceAddNumbers.AddNum(5,6);
}
}
Now save it and press "Generate WSDL" button, this will give you the WSDL file save it in your local system.
Go to Org B, Upload this WSDL file there. For this Go to App Setup-> Develop->Apex Classes->Click on "Generate from WSDL” button.
Now you can acces the above WSDL like
public with sharing class WSDLConnectionTest {
public integer c { get; set; }
public integer a{get;set;}
public integer b{get;set;}
public soapSforceComSchemasClassWebsrvcead.WebSrvceAddNumbers WSDL_Add{get;set;}
public WSDLConnectionTest()
{
a=5;
b=7;
partnerSoapSforceCom.Soap myPartnerSoap = new partnerSoapSforceCom.Soap();
// myPartnerSoap .endpoint_x = 'https://login.salesforce.com/services/Soap/u/21.0';
partnerSoapSforceCom.LoginResult LoginResult = myPartnerSoap .login('user@domain.com', 'XXXXXXXXXXX');
system.debug('____________Login Successful_______________________'+LoginResult);
WSDL_Add=new soapSforceComSchemasClassWebsrvcead.WebSrvceAddNumbers();
soapSforceComSchemasClassWebsrvcead.SessionHeader_element session= new soapSforceComSchemasClassWebsrvcead.SessionHeader_element();
system.debug('_______________Session___________________________'+session);
session.sessionId = LoginResult.sessionId;
system.debug('_______________Session__ID_________________________'+session.sessionId);
WSDL_Add.SessionHeader=session;
c=WSDL_Add.AddNum(a,b);
system.debug('_________Sum Is_____Controller______'+c);
// partnerSoapSforceCom.LoginResult LoginResult = myPartnerSoap.login('user@domain.com', 'XXXXXXXXXXX');
}
public void summ()
{
c=WSDL_Add.AddNum(a,b);
system.debug('_________Sum Is____ADD Method_______'+c);
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi Jain i din't understand why it is getting lots of code when we click on "Generate WSDl "button what's all those code may i know that.
Regards,
Praveen.