【问题标题】:Web Service returns an XML tag instead of valueWeb 服务返回 XML 标记而不是值
【发布时间】:2018-05-15 07:31:06
【问题描述】:

我遇到了一个问题,即我获取 XML 标记而不是仅获取值。

所以我的页面发送了 2 个数字,15 和 10 并且网络服务返回这个:

<?xml version="1.0" encoding="utf-8"?> 
<int xmlns="http://tempuri.org/">25</int> 

我不确定我是否在 Web 服务端或链接中遗漏了某些内容。

我只需要它返回 25 而不是整个 标签

链接按钮调用添加函数:

http://localhost/TestService/Service1.asmx/Add 

测试服务

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace TestsSimpleService
{

  //[WebService(Namespace = "http://tempuri.org/")]
    [WebService()]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public int Add(int a, int b)
        {
            return (a + b);
        }

    }
}

【问题讨论】:

    标签: asp.net web-services


    【解决方案1】:

    【讨论】:

    • 我较早发现并尝试过,但无法理解答案中的第二段。对我有帮助吗?
    • @maylin 如果您将 asmx 更改为 aspx 然后从 aspx 页面中删除所有 html 并返回(a + b) 将此代码替换为 Response.Write(a+b)
    • 从 aspx 页面中删除所有 html 是什么意思?
    • 在 aspx 页面中你会发现一些 html 代码删除它,使其成为空白页面
    猜你喜欢
    • 1970-01-01
    • 2012-02-26
    • 2023-04-05
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    相关资源
    最近更新 更多