I have a pretty simple ApiController that works fine on Win7, but on Windows 2003 Server I get an error.
Request for receipt (from browser or $ .getJson):
https://site.com:61656/AD/Authenticate?UserName=xxxx&Password=xxxxx&AuthKey=xxxxxx
I get the following error:
<Exception xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/System.Web.Http.Dispatcher">
<ExceptionType>System.InvalidOperationException</ExceptionType>
<Message>
No MediaTypeFormatter is available to read an object of type 'InputModel' from content with media type ''undefined''.
</Message>
<StackTrace>
at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger) at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger) at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<ExecuteBindingAsync>b__0(HttpParameterBinding parameterBinder) at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)
</StackTrace>
</Exception>
I use nuget overnight packages on 5/1/2012. It looks like the objectContent.Value object goes through null on Windows 2003 Server, but not on Windows 7 in the following line in HttpContentExtensions.cs:
if (objectContent != null && objectContent.Value != null && type.IsAssignableFrom(objectContent.Value.GetType()))
{
return TaskHelpers.FromResult((T)objectContent.Value);
}
Controller action:
[AcceptVerbs("GET", "POST")]
public ResultModel Authenticate(InputModel inputModel)
{
var test = ControllerContext.Request.Content.Headers.ContentType;
try
{
Console.WriteLine("AD Authorize request received: " + inputModel.UserName);
var ldap = new LdapAuthentication();
return ldap.Authenticate(inputModel);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return new ResultModel();
}
}
MediaType comes with a null value in Win7, but on a Windows 2003 server, the request never gets into the controller.
, "undefined"?
EDIT:
:
public class InputModel {
public string UserName { get; set; }
public string Password { get; set; }
public string AuthKey { get; set; }
}
(self host):
var config = new HttpsSelfHostConfiguration(ConfigurationManager.AppSettings["serviceUrl"]);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Routes.MapHttpRoute("default", "{controller}/{action}");
var server = new HttpSelfHostServer(config);
try
{
server.OpenAsync().Wait();
Console.WriteLine("Waiting...");
№ 2:
Win7 Windows 2003 Server. InputModel , Win7, Windows 2003 Server. Win7 JSON GET POST. Windows 2003 Server XML GET JSON POST.
InputModel POST. , , InputModel Windows 2003 Server, POST. , GET. jQuery $.getJSON Windows 2003 Server:
[AcceptVerbs("GET")]
public ResultModel Authenticate()
{
try
{
var inputModel = new InputModel();
var query = ControllerContext.Request.RequestUri.ParseQueryString();
inputModel.UserName = query.GetValues("UserName") != null ? query.GetValues("UserName")[0] : null;
inputModel.Password = query.GetValues("Password") != null ? query.GetValues("Password")[0] : null;
inputModel.AuthKey = query.GetValues("AuthKey") != null ? query.GetValues("AuthKey")[0] : null;
Console.WriteLine("AD Authorize request received: " + inputModel.UserName);
var ldap = new LdapAuthentication();
return ldap.Authenticate(inputModel);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return new ResultModel();
}
}