Sep 25, 2012

Creating Public Web-Service in Salesforce

We all are familiar with web services and we often use them. Now let's talk about other side of using web services by making them public so I don't need any authentication/passwords/SessionIds etc.

Recently I need to create a web service so it can used in a mobile app. Most of us know about Mobile SDK, REST, oAuth etc.. but in all I need to intake the credentials of salesforce organization to get access token or if am using web services then to get the session Id. But think about it, why end user will be concerned with the back-end/database? So all we need is a public web service which can be called to process our request.

So follow these simple steps:

1) Create a web service like this

global class DemoClass
{
    webService static string Method()
    {
        return 'DoSomething' ;
    }
}

2) Go to Site > Setup > App Setup > Develop > Sites > Select your Site > Give access of class "DemoClass" to site profile

3) Extract WSDL of your class, go to your class and then click "Generate WSDL". Now all we need to change the SOAP address.

Lets say, this is a snippet of my WSDL



Now we need to change the highlighted code like this:

This is the location:
https://ap1-api.salesforce.com/services/Soap/class/ankit/DemoClass

And our site URL is:

So our final location will be:
http://ankitarorasite-developer-edition.ap1.force.com/services/Soap/class/ankit/DemoClass

Now you can use this location in your WSDL and there will be no need of getting any access tokens or session Ids. Happy Coding.

58 comments:

  1. this is a great discovery. is that documented somewhere? I always thought it's impossible to have some anonymous webservices but you proved it's possible. thanks a lot.

    btw: it works the same way with REST services.

    ReplyDelete
    Replies
    1. Thank you so much, and glad that it helped :-)

      I searched a lot but it was not documented any where, that's motivated me to put this post.

      Am not sure about the REST as in webservices providing a location/endpoint URL depends on us.

      Delete
    2. REST works also:

      http://www.forcegenie.com/2012/09/28/anonymous-rest-webservices/

      Delete
  2. Can u provide more details on how to implement it exactly. I mean how to edit WSDL code and how to select site in Step 2. I am newbie in site development. Would be appreciable if you can help me on this.

    ReplyDelete
  3. I have a pdf site which uses a controller and some components and an object record id.

    How can I make it available without logging onto Salesforce.
    Please help.

    ReplyDelete
  4. One small but very useful post!

    You can see my post about APEX REST Web Services in Sites without authentication.

    http://salesforceafondo.wordpress.com/2013/02/28/como-crear-apex-soap-web-services-y-apex-rest-web-services-en-sites-publicos-en-force-com

    Regards.

    ReplyDelete
  5. Hi,
    can u tell me how to edit wsdl?

    ReplyDelete
  6. It's simply superb example. You are amazing. Thanks a lot.

    ReplyDelete
  7. Hey....what will be the output?

    ReplyDelete
  8. Hey i am new in Webservices and apex ...can anyone plz tell me what will be output.... how we will test this?

    ReplyDelete
  9. I have successfully created a public web service and I am trying to call it via angularjs on a different server and running into CORS issues, does salesfoce prevent calls from other servers?

    ReplyDelete
  10. Could you please let me know How did you Gave access of class "DemoClass" to site profile

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. I have made change in the xml ,how to call the webservice created?

    ReplyDelete
  13. I am getting Error: HTTP ERROR 405

    Problem accessing /services/Soap/class/DemoClass. Reason:
    GET not supported, this is a SOAP service, please use POST.

    ReplyDelete
    Replies
    1. I am getting the same error, did you resolve the issue?

      Regards.

      Delete
  14. My final URL is: https://merchants-products-developer-edition.ap1.force.com/services/Soap/class/DemoClass

    ReplyDelete
  15. thanks -- this is very useful. I am having a problem hitting the endpoint--it is fine when I hit it with a .NET app; however, I tried wiring up a httprequest from same SF org to hit it, and I consistently receive a StatusCode = 500. I am guessing I need to change my request, but I am not sure how. Any feedback?

    ReplyDelete
  16. i can't able to change my soap address location after generating wsdl.can anybody help me how to change.

    ReplyDelete
  17. Can I create dynamic objects? Means Need to create an object with fields in run time.Is that possible?
    Regards,
    Salesforce training in Chennnai

    ReplyDelete
  18. I want to know some basic ideas in sales force. Suppose I have a requirement to create a custom application which is a CRM system for school management using SFDC. My Doubts is, how can I create the custom application?
    Regards,
    Salesforce training in Chennai||Salesforce training institute in Chennai

    ReplyDelete
  19. Salesforce is the cloud based tool which is used by most of the professional who do CRM. Salesforce is the cost effective tool.
    salesforce training in chennai|salesforce training institute in chennai|salesforce training institutes in chennai|salesforce course in chennai

    ReplyDelete
  20. What i really like about salesforce is its user friendly UI and it is a cloud based tool so it can be accessed from any where. Also there is a mobile app and the features are such that any sales rep would fall for it.
    salesforce training chennai|best salesforce training in chennai|salesforce developer training

    ReplyDelete
  21. Cloud computing is the next big thing, through cloud the users have the liberty to use a shared network. The companies can focus on core business parts rather than investing heavily on infrastucture.
    cloud computing training in chennai|cloud computing courses in chennai|cloud computing training

    ReplyDelete
  22. Web-Design Deutschland und Web Development -Unternehmen in Deutschland E-Commerce- Website -Entwicklung, Web-Site -Design , Flash- Website usw. besuchen Sie uns @ http://www.accuratesolutionsltd.com/e-commerce-entwicklung/

    ReplyDelete
  23. Awesome Ankit!! how do we implement the same with an SSL Certificate!!!? I mean this is good for non SSL based clients but what if the client demands for SSL certificate.

    ReplyDelete
  24. your blog is so impressive ,its a great pleasure to see the post in your blog Amazon Web Services Training In Hyderabad

    ReplyDelete
  25. great article , Your post is very informative and helpful for us to improve my knowledge and skills.Amazon Web Services Training In Hyderabad

    ReplyDelete
  26. Your post is just outstanding! thanks for such a post,its really going great and great work.You have provided great knowledge about thr web design development and search engine optimization Website Design Company Bangalore | Website Development Company Bangalore

    ReplyDelete
  27. Great Work. This post is worth everyone’s attention. web design company in chennai

    ReplyDelete
  28. Very nice blog tanks for sharing. Keep updating. It will really helpful to us Web Designing Company Bangalore | Website Designing Company Bangalore

    ReplyDelete
  29. It was a fabulous post, i ever seen any where. Nicely managed post by admin. Web Services

    ReplyDelete
  30. Informative article, just what I was looking for.seo services chennai

    ReplyDelete
  31. A huge thanks to you for sharing this Blog your blog content is very nice ,I have read your blog your blog information is very usefull

    web hosting company in lucknow | Website designing Company in Lucknow | Domain Registration Service in lucknow | it Company in lucknow

    ReplyDelete
  32. interesting and important information about salesforce. Thanks for sharing this information. Salesforce CRM Services.

    ReplyDelete
  33. A huge thanks to you for sharing this Blog your blog content is very nice ,I have read your blog your blog information is very usefull

    Website designing Company in Lucknow | web development company in lucknow | seo company lucknow

    ReplyDelete
  34. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
    Sales Fore CRM Training in Chennai

    ReplyDelete
  35. I really appreciate information shared above. It’s of great help to us. If someone want to learn (ILT) instructor lead live training on AWS (Amazon Web Services) kindly Contact MaxMunus
    MaxMunus Offer World Class AWS Certification level classroom training, we have industry expert trainers. We provide Training Material and Software Support. MaxMunus has successfully conducted 1, 00,000 + trainings in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    Enroll for the live & interactive classroom training
    Arvind
    MaxMunus
    E-mail: arvind.sharma@maxmunus.com
    Skype id: arvind.sharma901
    Ph :( 0) 9019891304 / 080 - 41103383
    www.MaxMunus.com

    ReplyDelete
  36. Can truly relate and retain this outstanding post. Very well written. web design company Chennai

    ReplyDelete
  37. Very nice...thanks
    Very nice tutorial and nice blog about web services...thanks

    ReplyDelete
  38. Hey your blog is very nice, such useful information you are sharing. I really like your blog the information is very accurate and if you want to know more about free ad posting service,www.helpadya.com  there is another website with best information.

    ReplyDelete
  39. Nice post. Thanks for sharing this post and providing helpful information.
    Website Development Company in Lucknow provides various services like Website Designing & Development, Mobile Application Development and Digital Marketing.

    ReplyDelete
  40. What you mean with change the URL, as far the WSDL is generated is an static file, we need to download the file and re-import? what is the process?

    ReplyDelete

  41. Thanks for sharing this knowledgefull information.

    Business this day has become more competitive in nature to the extent that all business owners need to do something fast in order to remain in business. Proper collaboration is what most business needs to make progress in this competitive world. The experts here have what it takes to render highest quality and dedicated as well as targeted web development services which can give your customers what they need at any point in time. Through the result-oriented team working here you will be sure of getting premier website application development services that will meet the needs of your audience.

    Website application development
    Software Development Services
    Android App development Services

    ReplyDelete
  42. Thanks for sharing your fabulous idea. This blog is really very useful.web design services

    ReplyDelete
  43. Great list. I know many of them, but have now bookmarked several new ones. Thanks!I like This Blog Posting. I Will Recommend This Post to Our Friends.Web Design Sydney, Logo Design Sydney

    ReplyDelete
  44. Nice Information you have written here. Really Great Stuff. I keep it bookmark for our future purpose.
    We are also Web development Company in India who provide the services in Seo services Lucknow, Software Development Company In Lucknow, Web designing company in Lucknow,Visit Us today

    ReplyDelete
  45. Hi, thanks for the pretty post , interested to read about web design , keep more post
    web designing courses

    ReplyDelete
  46. Thanks for sharing your fabulous idea. This blog is really very usefu.
    AWS Jobs in Hyderabad

    ReplyDelete

  47. Web Design Sydney: It is a great sharing...I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. .Logo Design Sydney,Logo Design in Coimbatore,Brochure Design in Coimbatore

    ReplyDelete