代码之家  ›  专栏  ›  技术社区  ›  Ramiz Uddin

WebMethod返回为字符串(不带<?XML标签

  •  3
  • Ramiz Uddin  · 技术社区  · 15 年前
    [WebMethod(EnableSession=true)]
    [ScriptMethod(UseHttpGet=true, XmlSerializeString =  false)]
    public string RaiseCallbackEvent(string eventArgument)
    

    返回值开始于 <?xml . 我怎样才能摆脱它?

    1 回复  |  直到 11 年前
        1
  •  3
  •   DavidGouge    15 年前

    我想这是因为它是一个SOAP Web服务,而这正是SOAP Web服务所期望的。如果你想回来 只是 纯文本返回到客户机,我将创建一个ashx来手动处理请求。

    像这样(这是默认的通用处理程序脚手架)

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Test : IHttpHandler
    {
    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }
    
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }