function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KrishnakumarJKrishnakumarJ 

Example Sample HelloWorld WebService needed

I need examples for the foll:

1) How to create Sample HelloWorld WebService using Apex?.

2) How to generate WSDL for this Sample HelloWorld WebService ?. 

3) How to consume that Sample HelloWorldWebService in VisualForce page?..

 

Any Help would be appreciated.

 

 

 

 

 

 

jhenningjhenning
Apex class methods can be exposed as custom Force.com Web Services API calls. Use the webService keyword to define these methods. For example:
global class HelloWorldWebService {
webService static string sayHello(String h) {
h = 'Hello World!';
return h;
}
}
You can download a WSDL from the Apex class detail page:
  1. In the application navigate to Setup | Develop | Apex Classes.
  2. Click the name of a class that contains webService methods.
  3. Click Generate WSDL.
var docURL = "apex_web_services_methods.htm";var docVersion = "16.0";var docType="APEX";var docFunctionalArea = "Online Help/Tip Sheets";
KrishnakumarJKrishnakumarJ

Thank you for Replying to my ques.

 

Can you please send me the complete code for consume the Webservice in VisualSource Page (BestPractices)?.

 

Will be waiting for ur reply:)

KrishnakumarJKrishnakumarJ

Hi ,

While invking the HelloWorld WebService  from page I am getting the foll exception.

 

exception occured after webservc call.System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://ap1-api.salesforce.com/services/Soap/class/HelloWorldWebService

 

 

global class HelloWorldWebService {
   webService static string sayHello() {
        return 'Hello World!';
     }
}

 

public class HelloWorldWSContoller{
    String uname="KK";
    public String getUsername() {
        return uname;
    }
         
    public String getHelloWorld() {
        string result; 
        HelloworldServiceWSDL2Apex.HelloWorldWebService stub = new HelloworldServiceWSDL2Apex.HelloWorldWebService();
        uname = stub.sayHello();
        return result ;  
    } 
}

 

 

 

<apex:page controller="HelloWorldWSContoller" tabStyle="Account">
<apex:form >
        <!-- Define the JavaScript function sayHello-->
        <apex:actionFunction name="HelloWorld" action="{!getHelloWorld}"/>
    </apex:form>
      <apex:outputText value="{!Username}"/>
 <apex:outputText value="KK"/>

</apex:page>

 

Anyhelp is appreciated.

 

Thanks

KrishnakumarJKrishnakumarJ

After adding external server to Remote Sites, i am getting the following exception:

 

exception occured after webservc call.System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session faultcode=sf:INVALID_SESSION_ID faultactor=

Marty Y. ChangMarty Y. Chang

Hello, KrishnakumarJ.  I believe you need to set the sessionId after logging in, as shown in the code for the wrapper class in the following tutorial.

 

"NO-SOFTWARE Tutorial for Salesforce Web Services"

http://frombelvideres4thfloor.blogspot.com/2010/11/no-software-tutorial-for-salesforce-web.html

streetstreet

Hello Krishna,

 

Have you used two salesforce instances for this?

 

Even im working on same, can u brief the process of executing it.

 

Thanks.

SubhamSubham

hey street,

 

were you able to make this working?

 

even i need one example

 

Thanks,

 

16

 

 

SubhamSubham

same question to krishna too!!

were u able to solve this??

streetstreet

I was working on two sandbox instances. 

AnwarAnwar

Hi KrishnaKumar,

      i executed above code but i am getting some error

ErrorError: HelloWorldWSContoller Compile Error: Invalid type: HelloworldServiceWSDL2Apex.HelloWorldWebService at line 9 column 67

please tell me what i will do for execute that code

Thanks&Regards

ANWAR

csreddy7799csreddy7799

Hello Krishna can u provide your complete code, i am also trying to implement webservice..

anu.s1.3587621171560732E12anu.s1.3587621171560732E12

Hi am also getting the same error when I try to execute this one.

Error: HelloWorldWSContoller Compile Error: Invalid type: HelloworldServiceWSDL2Apex.HelloWorldWebService at line 9 column 67

 

can anyone solve this?

kodishkodish

Hi,

 

Did you execute these code? Is it code correct.

because

i have error occurred while save my apex class.

Ramesh KallooriRamesh Kalloori
Hi All,

I have created web service please go through the below code.

global class HelloWorldWebService { 
   webService static string sayHello() {
        return 'Hello World!'; 
     }
}
<apex:page controller="HelloWorldWSContoller" tabStyle="Account">
<apex:form >
{!val}
</apex:form>
</apex:page>
public class HelloWorldWSContoller{
    public String val{get;set;}
      public HelloWorldWSContoller()
      {
           val = HelloWorldWebService.sayHello();
      }      
}

and create the remote site settings as HelloWorldWebservice after generating WSDL from HelloWorldWebservice class. 


thanks,
Ramesh