Use this webService ( your web service is also ok )
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Services;
using MvcApplication1.Models;
using System.Web.Script.Services;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
namespace MvcApplication1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string testJSON(string a, string b, string c, string d, string e, string f)
{
string temp = "Data " + a + " " + b + " " + c + " " + d + " " + e + " " + f;
DataContractJsonSerializer serializer = new DataContractJsonSerializer(temp.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, temp);
string jsonString = Encoding.Default.GetString(ms.ToArray());
ms.Close();
return jsonString;
}
}
}
This is the page where it try to call the service (I made some changes to getProducts function):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function getProducts(a, b, c, d, e, f) {
$('#divResults').hide();
$('#divLoading').show();
try {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Service1.asmx/testJSON",
data: "{'a' : '1', 'b' : '2', 'c' : '3', 'd' : '4', 'e' : '5', 'f' : '6'}",
dataType: "json",
success: function (data) {
$('#divLoading').hide();
alert("Succeed");
$('#divResults').show();
$('#divResults').html(data.d);
},
error: function (result) {
$('#divLoading').hide();
alert('error: ' + error);
$('#divResults').hide();
}
});
}
catch (e) {
alert('failed to call web service. Error: ' + e);
$('#divLoading').hide();
}
}
</script>
</head>
<body>
<div id="divLoading" style="display:none">
Loading
</div>
<div id="divResults" style="display:none">
</div>
<button onclick="getProducts()">getProducts</button>
</body>
</html>
After you click on getProducts button "Succeed" alert will show and then divResults contains:
"Data 1 2 3 4 5 6"
Hope it helps