{"id":2436,"date":"2011-09-23T10:53:37","date_gmt":"2011-09-23T05:23:37","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2436"},"modified":"2011-09-23T10:53:37","modified_gmt":"2011-09-23T05:23:37","slug":"consume-salesforce-web-service-in-c-net-application","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/consume-salesforce-web-service-in-c-net-application\/","title":{"rendered":"Consume Salesforce Web service in C# .Net Application"},"content":{"rendered":"<p>In this example, we are going to consume the enterprise WSDL of the Salesforce in C# application.<\/p>\n<p>Log into the Salesforce and navigate to <strong>&#8220;Your Name | Setup | App Setup | Develop | API&#8221;\u009d<\/strong> and select the <strong>&#8220;Generate Enterprise WSDL&#8221;\u009d<\/strong>. \u00a0Copy the URL, as we will need this in our C# Application.<\/p>\n<p>Now Open Visual Studio (I am using Visual Studio 2010) and create new Windows Application. The UI of the application should look like:<\/p>\n<figure id=\"attachment_2437\" aria-describedby=\"caption-attachment-2437\" style=\"width: 460px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/C-Application-to-consume-salesforce-webservice.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2437 \" title=\"C# Application to consume salesforce webservice\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/C-Application-to-consume-salesforce-webservice.jpg?resize=460%2C158&#038;ssl=1\" alt=\"C# Application to consume salesforce webservice\" width=\"460\" height=\"158\" \/><\/a><figcaption id=\"caption-attachment-2437\" class=\"wp-caption-text\">C# Application to consume salesforce webservice<\/figcaption><\/figure>\n<p>Right click on the &#8220;<strong>References<\/strong>&#8220;\u009d folder and select &#8220;<strong>Add Service Reference<\/strong>&#8220;\u009d.<\/p>\n<figure id=\"attachment_2438\" aria-describedby=\"caption-attachment-2438\" style=\"width: 373px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/Add-Service-Reference-in-C.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2438\" title=\"Add Service Reference in C#\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/Add-Service-Reference-in-C.png?resize=373%2C126&#038;ssl=1\" alt=\"Add Service Reference in C#\" width=\"373\" height=\"126\" \/><\/a><figcaption id=\"caption-attachment-2438\" class=\"wp-caption-text\">Add Service Reference in C#<\/figcaption><\/figure>\n<p><!--more-->Now select the &#8220;<strong>Advanced<\/strong>&#8220;\u009d and then select &#8220;<strong>Add Web Reference&#8230;<\/strong>&#8220;\u009d<br \/>\nProvide the URL of the generated WSDL, which we have discussed above in this tutorial.<br \/>\nIt will prompt you for the username and password of salesforce, so provide it. After validation, it will display you below screen. Provide &#8221; the web reference name&#8221;\u009d which will be used in program. In this case, the web reference name is &#8220;<strong>SFDC_Enterprise_WSDL<\/strong>&#8220;\u009d.<\/p>\n<figure id=\"attachment_2439\" aria-describedby=\"caption-attachment-2439\" style=\"width: 498px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/Add-Web-reference-in-C.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2439 \" title=\"Add Web reference in C#\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/Add-Web-reference-in-C.png?resize=498%2C355&#038;ssl=1\" alt=\"Add Web reference in C#\" width=\"498\" height=\"355\" \/><\/a><figcaption id=\"caption-attachment-2439\" class=\"wp-caption-text\">Add Web reference in C#<\/figcaption><\/figure>\n<p>Add the following code in c# application:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Linq;\nusing System.Text;\nusing System.Windows.Forms;\nusing System.Web.Services.Protocols;\nusing SFDCWebServiceExample.SFDCCustom;\nusing SFDCWebServiceExample.SFDC_Enterprise_WSDL;\n\nnamespace SFDCWebServiceExample\n{\n    public partial class Form1 : Form\n    {\n        private SforceService binding;\n        private LoginResult lr;\n        private SaveExpenditureWebServiceService myBinding = new SaveExpenditureWebServiceService();\n\n        public Form1()\n        {\n            InitializeComponent();\n        }\n\n        private void btnLogin_Click(object sender, EventArgs e)\n        {\n\n            if (login())\n            {\n                describeGlobal();\n            }\n        }\n\n        private bool login()\n        {\n            try\n            {\n                binding = new SforceService();\n                binding.Timeout = 6000;\n                lr = binding.login(txtUserName.Text, txtPwd.Text);\n                return true;\n            }\n            catch (SoapException e)\n            {\n                MessageBox.Show(e.Message);\n            }\n            return false;\n        }\n        private void describeGlobal()\n        {\n            binding.Url = lr.serverUrl;\n            #region&#x5B;Consume Enterprise webservice]\n\n            binding.SessionHeaderValue = new SFDC_Enterprise_WSDL.SessionHeader();\n            binding.SessionHeaderValue.sessionId = lr.sessionId;\n            #endregion\n\n            \/\/describeGlobal returns an array of object results that\n            \/\/includes the object names that are available to the logged-in user\n\n            DescribeGlobalResult dgr = binding.describeGlobal();\n\n            \/\/Loop through the array echoing the object names to the console\n            StringBuilder sb = new StringBuilder();\n            for (int i = 0; i &lt; dgr.sobjects.Length; i++)\n            {\n                sb.Append(dgr.sobjects&#x5B;i].name+&quot; , &quot;);\n            }\n            MessageBox.Show(sb.ToString());\n        }\n   }\n}\n<\/pre>\n<p><strong>Note :<\/strong><br \/>\nAfter Successful login, set the &#8220;<strong>SessionHeaderValue&#8221;<\/strong> and <strong>&#8220;SessionHeaderValue.sessionId&#8221;<\/strong>, In this program, we are displaying the comma separated name of all the available objects available to logged in user.<\/p>\n<p>You can download the source code in <a title=\"create and consume webservice in salesforce\" href=\"https:\/\/jitendrazaa.com\/blog\/webtech\/salesforce\/create-a-custom-web-service-in-salesforce-and-consume-it-in-c-net-application\/\">next tutorial<\/a>.<\/p>\n<p>In <a title=\"consume and create web service in salesforce\" href=\"https:\/\/jitendrazaa.com\/blog\/webtech\/salesforce\/create-a-custom-web-service-in-salesforce-and-consume-it-in-c-net-application\/\">Next tutorial<\/a> we will discuss on creating the custom web service in salesforce and consuming it in .Net application using c#.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial is the demonstration of how to consume the web service from salesforce.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[22,9],"tags":[51,331],"class_list":["post-2436","post","type-post","status-publish","format-standard","hentry","category-csharp","category-salesforce","tag-c","tag-salesforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2445,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/create-a-custom-web-service-in-salesforce-and-consume-it-in-c-net-application\/","url_meta":{"origin":2436,"position":0},"title":"Create a custom Web service in Salesforce and consume it in C#.Net application","author":"Jitendra","date":"September 23, 2011","format":false,"excerpt":"In this tutorial, we will create the web service in salesforce and consume it in c#.Net application","rel":"","context":"In &quot;c#&quot;","block_context":{"text":"c#","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/csharp\/"},"img":{"alt_text":"Create Custom web service in salesforce using apex and consume using C#.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/09\/Create-Custom-web-service-in-salesforce-using-apex-and-consume-using-C.Net_.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":4501,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/using-soapui-with-salesforce-to-test-standard-and-custom-web-services-response\/","url_meta":{"origin":2436,"position":1},"title":"Using soapUI with Salesforce to test standard and custom web services response","author":"Jitendra","date":"May 27, 2015","format":false,"excerpt":"soapUI is most common tool available to test Soap based web services, it also has capability to test REST web services. soapUI can be used to test Partner WSDL, enterprise WSDL, Tooling API, Metadata API to study capability and response from Salesforce before writing any code in Java, C# or\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Create New SoapUI project","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/05\/Create-New-SoapUI-project.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/05\/Create-New-SoapUI-project.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/05\/Create-New-SoapUI-project.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3537,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/consuming-external-webservice-in-apex\/","url_meta":{"origin":2436,"position":2},"title":"Consuming External Web Service in Apex &#8211; Salesforce","author":"Jitendra","date":"October 13, 2013","format":false,"excerpt":"One of the feature we have in Salesforce is that we can easily consume External Web Services. In this article, we will learn step by step demo of consuming Web Service in Apex. There are many public websites available to consume Web Service and one of them, I am using\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Generating Apex from WSDL in Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/Generating-Apex-from-WSDL-in-Salesforce-1024x345.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/Generating-Apex-from-WSDL-in-Salesforce-1024x345.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/Generating-Apex-from-WSDL-in-Salesforce-1024x345.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2903,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-toolkit-for-php\/","url_meta":{"origin":2436,"position":3},"title":"Salesforce Toolkit for PHP","author":"Jitendra","date":"June 7, 2012","format":false,"excerpt":"Example of using PHP toolkit in Salesforce with Sample code","rel":"","context":"In &quot;Force.com&quot;","block_context":{"text":"Force.com","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/force-com\/"},"img":{"alt_text":"force.com toolkit for PHP toolkit","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/06\/force.com-toolkit-for-PHP-toolkit.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/06\/force.com-toolkit-for-PHP-toolkit.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/06\/force.com-toolkit-for-PHP-toolkit.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":6274,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/enterprise-territory-management-auto-account-assignment-using-apex\/","url_meta":{"origin":2436,"position":4},"title":"Enterprise Territory Management &#8211; Auto Account Assignment using Apex","author":"Jitendra","date":"September 22, 2017","format":false,"excerpt":"Use Apex code to auto assign Accounts on basis of Enterprise Territory Assignment rules","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Enterprise Territory - Auto Account Assignment using Apex","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Enterprise-Territory-Auto-Account-Assignment-using-Apex.jpg?fit=900%2C600&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Enterprise-Territory-Auto-Account-Assignment-using-Apex.jpg?fit=900%2C600&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Enterprise-Territory-Auto-Account-Assignment-using-Apex.jpg?fit=900%2C600&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Enterprise-Territory-Auto-Account-Assignment-using-Apex.jpg?fit=900%2C600&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":6951,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/mastering-visual-studio-and-salesforce-dx\/","url_meta":{"origin":2436,"position":5},"title":"Mastering Visual Studio and Salesforce DX","author":"Jitendra","date":"January 14, 2020","format":false,"excerpt":"3.5 hours of video to become Master on using and navigating Visual Studio, Need of scratch org and building modular application using Unlocked Packages","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce DX on Udemy","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/01\/Salesforce-DX-on-Udemy.png?fit=1200%2C693&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/01\/Salesforce-DX-on-Udemy.png?fit=1200%2C693&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/01\/Salesforce-DX-on-Udemy.png?fit=1200%2C693&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/01\/Salesforce-DX-on-Udemy.png?fit=1200%2C693&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/01\/Salesforce-DX-on-Udemy.png?fit=1200%2C693&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=2436"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2436\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}