Create a custom Web service in Salesforce and consume it in C#.Net application

In this tutorial, we will create the web service in salesforce and consume it in c#.Net application

In Previous article, we have consumed the standard enterprise wsdl of the salesforce. In this article we will create the webservice using apex in salesforce and consume it in C#.Net application.

In Salesforce create below class (using force.com IDE)

global public with sharing class SaveExpenditureWebService {

	webservice static Expenditure__c createExpenditure(Decimal amount,String expName, String paidByName )
	{
		Expenditure__c c = new Expenditure__c();
		Person__c p = [Select p.Name From Person__c p Where Name = :paidByName limit 1];
		c.Amount__c = amount;
		c.Name = expName;
		c.Exp_Date__c = Date.today();
		c.Paid_By__c = p.Id;
		insert c;

		return c;
	}
}

Note:

  • Apex class in which webservice is going to be written must be declared “global“.
  • Keyword “webservice“ must be used for a method which should be exposed as a webservice.
  • Method must be declared as static.

In above code, I am using a custom object “Expenditure__c“ to insert into Salesforce.  Any type of code can be written.
Now in C#, create windows application with following controls:

Create Custom web service in salesforce using apex and consume using C#.Net
Create Custom web service in salesforce using apex and consume using C#.Net

Continue reading “Create a custom Web service in Salesforce and consume it in C#.Net application”

Consume Salesforce Web service in C# .Net Application

Author posted by Jitendra on Posted on under category Categories c#, Salesforce and tagged as Tags , with 14 Comments on Consume Salesforce Web service in C# .Net Application

This tutorial is the demonstration of how to consume the web service from salesforce.

In this example, we are going to consume the enterprise WSDL of the Salesforce in C# application.

Log into the Salesforce and navigate to “Your Name | Setup | App Setup | Develop | API” and select the “Generate Enterprise WSDL”.  Copy the URL, as we will need this in our C# Application.

Now Open Visual Studio (I am using Visual Studio 2010) and create new Windows Application. The UI of the application should look like:

C# Application to consume salesforce webservice
C# Application to consume salesforce webservice

Right click on the “References“ folder and select “Add Service Reference“.

Add Service Reference in C#
Add Service Reference in C#

Continue reading “Consume Salesforce Web service in C# .Net Application”

Access Modifiers / Specifiers in C# Language

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with 1 Comment on Access Modifiers / Specifiers in C# Language

Available Access Modifiers / Specifiers in C# Language

Access Modifiers (Access Specifiers) describes as the scope of accessibility of an Object and its members. All C# types and type members have an accessibility level . We can control the scope of the member object of a class using access specifiers. We are using access modifiers for providing security of our applications. When we specify the accessibility of a type or member we have to declare it by using any of the access modifiers provided by CSharp language.

C# provide five access specifiers , they are as follows :

  • public
  • private
  • protected
  • internal
  • protected internal

public :

public is the most common access specifier in C# . It can be access from anywhere, that means there is no restriction on accessibility. The scope of the accessibility is inside class as well as outside. The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private :

The scope of the accessibility is limited only inside the classes or struct in which they are declared. The private members cannot be accessed outside the class and it is the least permissive access level.

protected :

The scope of accessibility is limited within the class or struct and the class derived (Inherited )from this class.

internal :

The internal access modifiers can access within the program that contain its declarations and also access within the same assembly level but not from another assembly.

protected internal :

Protected internal is the same access levels of both protected and internal. It can access anywhere in the same assembly and in the same class also the classes inherited from the same class .

Microsoft Visual C# 2008 Compiler could not be created. QueryService for ‘{7D960B16-7AF8-11D0-8E5E-00A0C911005A} failed

Resolve error – Microsoft Visual C# 2008 Compiler could not be created. QueryService for ‘{7D960B16-7AF8-11D0-8E5E-00A0C911005A} failed

While i was working on Console application, suddenly i get below error saying – Microsoft Visual C# 2008 Compiler could not be created. QueryService for ‘{7D960B16-7AF8-11D0-8E5E-00A0C911005A} failed.

To resolve this error, i re-installed the visual studio, but it didn’t helped me.
Then i run below command –


C:Program FilesMicrosoft Visual Studio 9Common7IDE devenv.exe /resetsettings

It also, not worked.

Then i searched for below command and it worked very well.

C:Program FilesMicrosoft Visual Studio 9Common7IDEdevenv.exe /ResetSkipPkgs

Tutorial – Read and export excel file in ASP.Net using C#

Author posted by Jitendra on Posted on under category Categories ASP.NET, c# and tagged as Tags , with 1 Comment on Tutorial – Read and export excel file in ASP.Net using C#

Tutorial – Read and export excel file in ASP.Net using C#

Hi Readers,
In this article, i am going to show you that how to read excel file in C# and exporting it into ASP.Net. You might need this type of code when you want to read the file from server and export to the client.
Following will be the application look like :

Read And Export Excel in ASP.Net
Read And Export Excel in ASP.Net

Continue reading “Tutorial – Read and export excel file in ASP.Net using C#”

Virtual, Override and new Keyword in C#

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with 5 Comments on Virtual, Override and new Keyword in C#

Virtual, Override and new Keyword : Polymorphism , Method Hiding and Overriding in C#

Consider following class Hierarchy:

Multilevel Inheritance
Multilevel Inheritance

In this example, we will consider three classes which are TestA, TestB and TestC. Continue reading “Virtual, Override and new Keyword in C#”

Final Keyword in C# – sealed with const and readonly

Author posted by Jitendra on Posted on under category Categories c# and tagged as Tags with 1 Comment on Final Keyword in C# – sealed with const and readonly

Example of Final Keyword in C# – sealed with const and readonly

In java there is keyword “final“, which is used to avoid overloading / inheritance of method / class respectively.

In c# there is no keyword like “final” but the same thing is achieved by keyword “sealed“.

A class which is marked by keyword sealed cannot be inherited.

If you have ever noticed, structs are sealed. You cannot derive a class from a struct. Continue reading “Final Keyword in C# – sealed with const and readonly”

This row already belongs to another table – Error

Author posted by Jitendra on Posted on under category Categories c#, Microsoft and tagged as Tags with 2 Comments on This row already belongs to another table – Error

This row already belongs to another table – Error resolved

A beginner in C#, most of the time get error “This row already belongs to another table” while adding Row from one DataTable to another DataTable.

The reason of this error is that, we cannot add row of one table into another directly, we have to use the API of C# as shown below:

Continue reading “This row already belongs to another table – Error”

Cross-thread operation not valid – error solved in C#

Author posted by Jitendra on Posted on under category Categories c#, Tech Tips and tagged as Tags with Leave a comment on Cross-thread operation not valid – error solved in C#

Cross-thread operation not valid – error solved in C#

For the beginners, working on thread might come across the error saying “Cross-thread operation not valid“. This type error comes normally when Windows control created in one thread and accessed in another.
Because the Windows control are not thread safe by default.

ThreadCommunication
Thread Communication

Continue reading “Cross-thread operation not valid – error solved in C#”

MSMQ – Microsoft Message Queue Introduction

Author posted by Jitendra on Posted on under category Categories c#, Microsoft and tagged as Tags , , with 2 Comments on MSMQ – Microsoft Message Queue Introduction

How to Install MSMQ, MSMQ – Microsoft Message Queue Introduction, Types of Queue, Modes of Queue, System Queue

Microsoft Message Queue (MSMQ):
MSMQ is a messaging protocol that allows applications running on separate servers/processes to communicate in a failsafe manner. A queue is a temporary storage location from which messages can be sent and received reliably, as and when conditions permit. Queues are used to receive and send the Messages.

To Install MSMQ, Go to Control Panel -> Add Remove Program -> Add Windows Component and select “Message Queuing”

Install MSMQ - Microsoft Messaging Queue
Install MSMQ - Microsoft Messaging Queue

Continue reading “MSMQ – Microsoft Message Queue Introduction”