Calling External Web Services from – Part I: Hosting your web service

Part I: Hosting your web service
Part II: Opening your web service to the internet
Part III: Building an Apex class that calls your web service

The other day, I read about the ability to call external web services from, and decided to give it a try. I come from a Microsoft programming background, so I expected it to be simple & straightforward. I ended up jumping through hoops, and by the end of it, I had already decided to write this post to save others the trouble.

I decided to break the whole process down into four parts -
Part 1 – will focus on how to build the webservice that we will be using.
Part 2 – will focus on how to make the webservice accessible to from the Internet.
Part 3 – will focus on the Apex code etc. required on the Salesforce side to call the web service.
Part 4 – will focus on advanced issues like error handling, arrays etc.

In this part, we will simply build an old-fashioned web service. Since this is a fairly routine task for any programmer worth his salt, I will keep the instructions as concise as I can. So, here goes:-

  • Launch Visual Studio – I am using Visual Studio 2008. Create a new Asp.Net web service (File->New->Project->Visual C#->Asp.Net Web Service Application). Name it “MyWebService”, and hit Ok.


  • Hitting Ok should automatically generate a basic web service. In the solution explorer (View->Solution Explorer), there should already by a web service file named [Service1.asmx], and the corresponding C# code file [Service1.asmx.cs].
  • Hit F5, or go to Debug->Start Debugging from the menu to execute the web service. It should show you a page like the one below -


  • Next, you need to make sure that IIS is running on your machine. You can go to Start->{Type IIS in the search box}. This should launch IIS on your machine. If you don’t have it installed, you can visit this link to see how to install IIS.
  • Navigate to the IIS root folder- this is usually C:\inetpub\wwwroot. Create a new directory called “MyWebService” here. You will need administrative privileges on the machine for this.


  • Next, we are going to “Publish” the web service. Publishing is the process where the web service is actually “hosted” on IIS, instead of within visual studio.
  • In Solution Explorer, right-click on the project name, and select “Publish…”. In the “Publish Web” dialog box that comes up, click the ellipsis next to “Target location”, and navigate to the folder we just created.


  • Make sure that you select the option “All project files” in the “Copy” section on the dialog box. and click “Publish”.
  • Once the publish is done, try navigating to http://localhost/MyWebService/Service1.asmx. If everything is setup correctly, this should bring up the web service page.

That wraps up our first part – creating a bare bones web service. In the next post, we will see how to expose this web service to the internet so that can call it.

1 comment:

  1. Can you give the url link for part 4?