WRITE AN APEX CLASS AS FOLLOWS(ADDITION OF TWO NUMBERS)
Consumming Apex webservice in C# .net
<!-- Web Services API : WebServiceMath -->
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-->
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();
}
}
}
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{
webService static Integer add(Integer a,Integer b)
{
return a+b;
}
}
<!-- Web Services API : WebServiceMath -->
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.
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
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