I've got an MVC application that accepts eitherJSON or XML objects dpen开发者_开发知识库ding on the request type. This application is based on this article
To call a method on the MVC application that requires a complex object, I use the following Javascript (JQuery):
function GetUnassignedJob() {
if (isInteger($('#txtDay').val()) && isInteger($('#txtMonth').val()) && isInteger($('#txtYear').val()) && isInteger(intCurrentJobSummaryIndex) && intCurrentJobSummaryIndex > -1) {
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: 'http://server/api/wip/joboptimise/getlistforids/' + $('#txtYear').val() + '/' + $('#txtMonth').val() + '/' + $('#txtDay').val(),
data: $.toJSON(aJobSummary[intCurrentJobSummaryIndex].JobIds),
dataType: 'json',
cache: false,
beforeSend: function(XMLHttpRequest) { ShowLoading(); },
success: function(data, textStatus) {
try {
ClearUnassignedJobs();
AddUnassignedJobs(data);
}
catch (e) {
alert('GetUnassignedJob():\r\n\r\n' + e.message);
HideLoading();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
HideLoading();
ShowStatus('unable to retrieve job list');
},
complete: function(XMLHttpRequest, textStatus) {
HideLoading();
}
});
}
else {
ShowStatus('please ensure you have entered numeric values for day, month and year');
}
}
When deployed to the server and accessed from any client on the network - everything works fine. However, when I try to to the same from the server, I receive the following error message:
Page Location: /api/wip/joboptimise/getlistforids/2010/3/10
Message: Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''.
Source: System.ServiceModel.Web
Method: System.Object InternalReadObject(System.Runtime.Serialization.XmlReaderDelegator, Boolean)
Stack Trace: at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName) at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader) at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(Stream stream) at rbm.api.ObjectFilter.ProcessJson(ActionExecutingContext filterContext)
Some further investigation shows that the InputStream property of the HttpContext is empty! Stranger still, when I use an application like TcpTrace (so that I can see the HTTP traffic), everything works!
Any assistance would be greatly appreciated,
Mark
The prior comments are right, using local host. You could edit your hosts file located at: windows\system32\drivers\etc on your server and add an entry that maps local host to the URL
127.0.0.1 www.xyz.com
精彩评论