I am following various online examples without any success. I am merely trying to create an initial example that passes a value to a web service call.
What am I doing wrong?
I can do this EASILY with HttpHandlers...something this simple shouldn't be THIS hard?
UPDATED:
The reason it was failing is because the "contentType" attribute was missing. This was outlined in the following answer.
Here Is The Error I Keep Getting:
System.InvalidOperationException: Missing parameter: key.\r\n at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)\r\n at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)\r\n at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()\r\n at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
This Is The HTML:
<script type="text/javascript">
var url = '<%=ResolveUrl("~/Services/ProjectDialog.asmx/TryThis")%>';
function callWebService() {
jQuery.ajax({
cache: false,
type: 'POST',
complete: onComplete,
data: '{ "key": 42 }',
dataType: 'application/json; charset=utf-8',
error: onError,
success: onSuccess,
url: url
});
}
function onComplete(status, xmlHttpRequest) {
var stop = "";
}
function onError(xmlHttpRequest, status, error) {
var stop = "";
}
function onSuccess(data, status, xmlHttpRequest) {
var stop = "";
}
jQuery(document).ready(function() {
});
</script>
<input type="button" value="Run Web Service" onclick="callWebService();" />
This Is The Web Service:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
namespace My.Services
{
/// <summary>
/// Summary description for ProjectDialog
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class ProjectDialog : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string TryThis(Int32 key)
{
return key.ToString();
}
}
}