ASMX返回纯字符串 [英] ASMX Returning a pure string
问题描述
我有一个ASP.NET Web服务(.asmx).我的服务定义如下:
I have an ASP.NET web service (.asmx). My service is defined like the following:
[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;
}
}
当前,如果我调用此服务方法,则会得到以下结果:
Currently, if I call this service method, I get the following result:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">even</string>
我的问题是,我只需要返回字符串部分.我不想返回包装的XML.我该如何使用.asmx?
My issue is, I need to return just the string part. I do NOT want to return the wrapping XML. How do I do this with an .asmx?
谢谢!
推荐答案
是否需要为此.asmx
Web服务?我的意思是,通过排除SOAP信封,您实际上是在说这不是SOAP Web服务",所以为什么不更进一步,将其设置为常规的.aspx
页面而不是.asmx
Web页面服务.
Does it need to be an .asmx
web service for this? I mean, by excluding the SOAP envelope you're essentially saying "this is not a SOAP web service" as it is, so why not take it a step further and make it a regular .aspx
page instead of an .asmx
web service.
作为页面,您想要做的事情将是微不足道的.删除页面上的所有标记,使用Response.Headers
相应地编辑响应标题,使用Response.Write()
输出原始文本,使用Response.End()
关闭响应.
As a page, what you're trying to do would be trivial. Remove all mark-up from the page, use Response.Headers
to edit the response headers accordingly, Response.Write()
to output your raw text, and Response.End()
to close the response.
这篇关于ASMX返回纯字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!