Labels

Thursday, April 26, 2012

Consuming Apex webservice in C# .net,Consume Apex webservice in C# .net,c#,Salesforce.com,Salesforce.com webservices,apex webservices,web,webservices,csharp webserviceConsuming, Apex webservice,in C# .net


WRITE AN APEX CLASS AS FOLLOWS(ADDITION OF TWO NUMBERS) 
Consumming Apex webservice in C# .net


global with sharing class WebServiceMath
{
webService static Integer add(Integer a,Integer b)
{
return a+b;
}
}
Save the code.... Click on generate from WSDL Button,You will get
<!-- Web Services API : WebServiceMath -->
<definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://soap.sforce.com/schemas/class/WebServiceMath"targetNamespace="http://soap.sforce.com/schemas/class/WebServiceMath">.....................................................................................................................................
Copy the URL Of WSDL

Then go to VisualStudio

Web hosting
Right Click on Sulution Add WebReferencs
copy:https://ap1.salesforce.com/services/wsdl/class/WebServiceMath
and click on go u will get proxy.---->com.salesforce.ap11
Then come back to apex

App Setup-->dev-API-->
Partner WSDL
A loosely typed WSDL for customers, partners, and ISVs who are building client applications for multiple organizations. It can be used to access data within any organization.
Generate Partner WSDL--click on link

 u get wsdl https://ap1.salesforce.com/services/wsdl/apex
copy this link
Go to VisualStudio
Add webreference past the link and go
give name as ---->sForceService
u get another proxy 

Create Asp.NetPage
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebService._Default" %>
<html>
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        A:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        B:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="ADD" onclick="Button1_Click" />
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
 
Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Runtime;
using System.Web.Services;
using System.Web.Services.Protocols;
using WebService.com.salesforce.ap11;
using WebService.sForceService;
namespace WebService
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SforceService o = new SforceService(); 

 LoginResult lr     =o.login("UserName@gmail.com","password+Security Token");
//u get Security Token in      personalsetup
      WebService.sForceService.SessionHeader sh = new WebService.sForceService.SessionHeader();
           
            sh.sessionId = lr.sessionId;
            o.Url = lr.serverUrl;
            o.SessionHeaderValue = sh;
           com.salesforce.ap11.WebServiceMathService obj = new com.salesforce.ap11.WebServiceMathService();
           obj.SessionHeaderValue = new WebService.com.salesforce.ap11.SessionHeader();
          obj.SessionHeaderValue.sessionId=sh.sessionId;
           //obj.Timeout = "6000";
            Label1.Text = obj.add(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)).ToString();
        }
    }
}
 

 
 


No comments:

Post a Comment