开发者

return flat text from .net webservice?

开发者 https://www.devze.com 2023-01-28 17:41 出处:网络
I have function calledgetdoctor () in asmx file I wannna call this webmethod from javascriptand get the result into flat text i.ei wanna get the name doctor name n开发者_StackOverflow社区ot in neither

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

精彩评论

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

关注公众号