开发者

return flat text from .net webservice?

I have function called getdoctor () in asmx file I wannna call this webmethod from javascript and get the result into flat text i.e i wanna get the name doctor name n开发者_StackOverflow社区ot in neither in xml or json


ASMX web services doesn't support this. You could write a generic handler .ashx:

<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;

public class Handler : IHttpHandler 
{
    public void ProcessRequest(HttpContext context) 
    {
        context.Response.ContentType = "text/plain";
        context.Response.Write("some plain text");
    }

    public bool IsReusable 
    {
        get { return true; }
    }
}

Now you could call your handler from javascript: http://yoursite.com/getdoctor.ashx.

Another option is to use WCF.


If you don't want any wrapping, why expose it as asmx? Just a vanilla handler (ashx) would be fine - just write text to the response and set the content-type to text/plain

With MVC you could just return a string from an action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜