[Mono-aspnet-list] SOLVED ScriptService with JSON instead of WebService -- how?
Mikko Vuoti
vuoti at iki.fi
Fri Nov 30 21:50:53 UTC 2012
Mono rules, mistakes were mine:
1) I called with $.ajax( { ..., type:"POST", ...} ), but gave the
method arguments GET-style, as url query string ("?name=bob")
=> arguments have to be given as $.ajax(..., data:"{ name:\"bob\" }"
Also contentType:"application/json" has to be set,
whereas dataType:"json" seems to be optional in my setup
2) I did not have a properly configured Web.config file in the
applications root directory; therefore, the handlers/factories
required for properly processing ScriptMethod queries were not
registered.
=> Easiest way of creating a properly configured Web.config is
to go to application root and to issue "mconfig --target=web af AJAX".
Easy enough!
3) The minimal attribute set required for ScriptMethods are
[WebService] for the service class
[WebMethod] and [ScriptMethod] for the method.
And thanks Mike and Edgar for your ideas!
best wishes,
Mikko
----------------------------------------------------------------------
Message: 1
Date: Thu, 22 Nov 2012 19:17:39 +0200
From: "Mikko Vuoti" <vuoti at iki.fi>
To: <mono-aspnet-list at lists.ximian.com>
Subject: [Mono-aspnet-list] ScriptService with JSON instead of
WebService -- how?
Message-ID: <29D60FB00C474F48A3CD34D2BB738D03 at Pohisija>
Content-Type: text/plain; charset="us-ascii"
There seems to be a few questions and answers around on this subject, but so
far I have not found the missing piece of wisdom to get my script service
working.
I want to create a service to be consumed by a jQuery.Ajax driven javascript
app. However, I can't get the method configured so that it would return JSON
instead of XML.
Here is the trivial C#
======================
using System;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
namespace ScriptServiceTest
{
[ScriptService]
public class MyService : WebService
{
[ScriptMethod]
public string Hello(string name)
{
return("Hello, " + name);
}
}
}
======================
I have added the reference to System.Web.Extensions.
I have also generated the web.config (mconfig --target=web af AJAX), not
sure if this has to do with the problem, though.
The code above doesn't make the service available. If I add
[WebService]/[WebMethod] attributes to the class/method definition the
method becomes available as a regular web service, i.e. it returns XML - not
JSON.
I've been testing on Mono / .NET 3.5 and 4.0.
Any pointer to a resource explaining how script services should be set up
with mono is warmly welcome!
thanks your time!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20121122/ed8
00d89/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 26 Nov 2012 13:36:04 -0200
From: Edgar <edgarrc at gmail.com>
To: <mono-aspnet-list at lists.ximian.com>
Subject: [Mono-aspnet-list] RES: ScriptService with JSON instead of
WebService -- how?
Message-ID: <00f801cdcbeb$c2449500$46cdbf00$@com>
Content-Type: text/plain; charset="us-ascii"
Maybe this solution can help you, see all answers.
http://stackoverflow.com/questions/11088294/asp-net-asmx-web-service-returni
ng-xml-instead-of-json
Edgar
De: mono-aspnet-list-bounces at lists.ximian.com
[mailto:mono-aspnet-list-bounces at lists.ximian.com] Em nome de Mikko Vuoti
Enviada em: quinta-feira, 22 de novembro de 2012 15:18
Para: mono-aspnet-list at lists.ximian.com
Assunto: [Mono-aspnet-list] ScriptService with JSON instead of WebService --
how?
There seems to be a few questions and answers around on this subject, but so
far I have not found the missing piece of wisdom to get my script service
working.
I want to create a service to be consumed by a jQuery.Ajax driven javascript
app. However, I can't get the method configured so that it would return JSON
instead of XML.
Here is the trivial C#
======================
using System;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
namespace ScriptServiceTest
{
[ScriptService]
public class MyService : WebService
{
[ScriptMethod]
public string Hello(string name)
{
return("Hello, " + name);
}
}
}
======================
I have added the reference to System.Web.Extensions.
I have also generated the web.config (mconfig --target=web af AJAX), not
sure if this has to do with the problem, though.
The code above doesn't make the service available. If I add
[WebService]/[WebMethod] attributes to the class/method definition the
method becomes available as a regular web service, i.e. it returns XML - not
JSON.
I've been testing on Mono / .NET 3.5 and 4.0.
Any pointer to a resource explaining how script services should be set up
with mono is warmly welcome!
thanks your time!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20121126/388
78b61/attachment-0001.html>
------------------------------
_______________________________________________
Mono-aspnet-list mailing list
Mono-aspnet-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-aspnet-list
End of Mono-aspnet-list Digest, Vol 45, Issue 11
************************************************
More information about the Mono-aspnet-list
mailing list