Interviews2 answers
How to make a method of a web service class accessible through the internet?
2 Answers
First create asmx class file and in that file write this below code web service method
///
/// Summary description for CommonWebService
///
[WebService(Namespace = "http://microsoft.com/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class CommonWebService : System.Web.Services.WebService
{
BaseBL objBaseBL = new BaseBL();
public CommonWebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
//Retrieve record or fetch data on Enitity name and field name
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public string RetrieveRecordExists(string name, string entity)
{
string result = "";
DataSet ds = new DataSet();
ds = objBaseBL.RetrieveRecordExists(name, entity);
if (ds != null)
{
result = ReturnJson.GetJson(ds);
}
return result;
}
}
/// call this method with java script and jason
Milind biloniaPosted Jun 10, 2016, 10:36 PM EDT
By qualifying the method with the WebMethod attribute.
For Example:
C#
[WebMethod()]
public string MethodName()
[WebMethod()]
public string MethodName()
VB
<WebMethod()> _
Public Function MethodName() As String
<WebMethod()> _
Public Function MethodName() As String
Purushottam RathorePosted Mar 3, 2011, 9:43 AM EST
