Hi I'm trying to post json to a self-hosting wcf service which uses WebHttpBinding/WebHttpBehaviour. By self-hosting I mean that I am creating my own service host and overriding its InitializeRuntime rather than using IIS and a .svc file (code sample below).
For brevity I have not posted a full running example as it would be fairly complex to recreate the code to serve the javascript but I have extracted out hopefully enough details to identify whether this issue is something I'm doing wrong or a bug in the current version of mono. The long and short of it is that running under mono 2.6.3 on windows 7, I get the following error: 415 Expected content-type 'application/xml; charset=utf-8' but got 'application/json; charset=UTF-8 However this works perfectly when running on .NET and I am trying to post json so I would expect that the request content type should surely be application/json and not application/xml as stated above? Request headers: Via 1.1 MYPROXY Content-Length 0 Date Fri, 16 Apr 2010 15:23:31 GMT Server Mono-HTTPAPI/1.0 Host MYPC:8000 User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 Accept text/javascript, text/html, application/xml, text/xml, */* Accept-Language en-gb,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 115 Proxy-Connection keep-alive X-Requested-With XMLHttpRequest X-Prototype-Version 1.6.1 Content-Type application/json; charset=UTF-8 Referer http://MYPC:8000/ Content-Length 19 Request body: {} public class MyServiceHost : ServiceHost private Type iServiceInterfaceType; public MyServiceHost (Type aServiceImplementationType, Type aServiceInterfaceType, params Uri[] aBaseAddress) { base.InitializeDescription(aServiceImplementationType, new UriSchemeKeyedCollection(aBaseAddress)); this.iServiceInterfaceType = aServiceInterfaceType; } protected override void InitializeRuntime() { ServiceEndpoint endpoint = this.AddServiceEndpoint(iServiceInterfaceType, new WebHttpBinding(), String.Empty); endpoint.Behaviors.Add(new WebHttpBehavior()); base.InitializeRuntime(); } } My service interface looks something like this: [ServiceContract] interface IMyService { [OperationContract, WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] Guid Open(); } and I am invoking it from my javascript client using a Prototype request looking like the following: var sendRequest = function(url, requestData, callback) { return new Ajax.Request(url, { method: 'post', postBody: Object.toJSON(requestData), onSuccess: function(transport) { var result = transport.responseJSON; if (callback) { try { callback(eval("result." + methodName + "Result")); } catch (e) { if (typeof console != "undefined") { console.log("Exception caught in callback eval." + e); } } } }, onFailure : function (transport){ if (typeof console != "undefined") { console.log("JSON Request error: " + transport.statusText); } }, contentType: "application/json" }); var myURL = "..."; sendRequest(myURL, {}, function (result) {alert(result);} }; Anyone who can shed light on what I'm doing wrong, I'd be very grateful. Regards Iain Mcleod -- View this message in context: http://n4.nabble.com/WCF-JSON-POST-get-error-415-expected-content-type-application-xml-not-application-json-tp2013204p2013204.html Sent from the Mono - General mailing list archive at Nabble.com. _______________________________________________ Mono-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-list
