I am working on an asp.net application.
I have created a WebServices which has WebMethod Called "BindCategory" which returns List of News-Category.The WebService in my application as :
namespace MobileNewsAppication
{
/// <summary>
/// Summary description for MobileServices
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[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 MobileServices : System.Web.Services.WebService
{
public class NewsCategory
{
public long Category_ID { get; set; }
public string Category_Name { get; set; }
public string QFlag { get; set; }
}
[WebMethod)]
public NewsCategory[] BindCategory()
{
DataTable dt = new DataTable();
List<NewsCategory> details = new List<NewsCategory>();
using (SqlConnection con = new SqlConnection(Connection))
{
SqlCommand cmd = new SqlCommand("AllCategory_Select", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dtrow in dt.Rows)
{
NewsCategory Category = new NewsCategory();
Category.Category_Name = dtrow["Category_Name"].ToString();
Category.Category_ID = Convert.ToInt64(dtrow["Category_ID"].ToString());
details.Add(Category);
}
}
return details.ToArray();
}
}
}
Now i have deployed this Webservice on service.
Now i have created another asp.net application and i am trying to access that WebService which is on Server.
My Code to access the Web Method as:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js">
</script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "http://webcall.com/MobileServices.asmx/BindCategory",
data: "{}",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
async: true,
success: OnSuccess,
error: OnError
});
function OnSuccess(data) {
$.each(data.d, function (key, value) {
$("#ulCategory").append("<li>" + value.Category_Name + "</li>");
})
}
function OnError(data) {
alert('fail');
}
});
</script>
</head>
<body>
<div>
<div style="width:200px;height:600px; background-color:#e8e8e8; float:left;">
Category
<ul id="ulCategory">
</ul>
</div>
</div>
</body>
</html>
But I am unable to access that WebMethod which is on server.I have also added a webreference of that webservice which is on server but It returns to error function.
Please Help me Here.