ASMX返回纯字符串

use*_*662 5 c# asmx

我有一个ASP.NET Web服务(.asmx).我的服务定义如下:

[System.Web.Services.WebService(Namespace = "http://tempuri.org/")]
[System.Web.Services.WebServiceBinding(ConformsTo = System.Web.Services.WsiProfiles.BasicProfile1_1)]
public class MyService : System.Web.Services.WebService
{
  [System.Web.Services.WebMethod]
  public string GetResult()
  {
    string result = "";

    int day = System.DateTime.UtcNow.Day;
    if ((day % 1) == 1)
      result = "odd";
    else
      result = "even";
    return result;
  }
}
Run Code Online (Sandbox Code Playgroud)

目前,如果我调用此服务方法,我会得到以下结果:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">even</string>
Run Code Online (Sandbox Code Playgroud)

我的问题是,我需要只返回字符串部分.我不想返回包装XML.如何使用.asmx执行此操作?

谢谢!

Dav*_*vid 4

是否需要.asmx为此提供网络服务?我的意思是,通过排除 SOAP 信封,您实际上是在说“这不是 SOAP Web 服务”,所以为什么不更进一步,将其设为常规页面.aspx而不是.asmxWeb 服务。

作为一个页面,您想要做的事情将是微不足道的。从页面中删除所有标记,用于Response.Headers相应地编辑响应标头,Response.Write()输出原始文本,并Response.End()关闭响应。