繁体   English   中英

从 Postman 调用简单的 C# Web 服务方法时出现问题

[英]Problem calling a simple C# Webservice method from Postman

我使用 C# 创建了一个非常简单的 Web 服务

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

namespace Receival
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    
    public class ReceiveService : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string Mirror(string request)
        {
            return request;
        }
    }
}

我正在使用 Postman 进行测试。

HelloWorld() 工作正常

Mirror() 返回错误:

System.InvalidOperationException:请求格式无效:文本/纯文本。 在 System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

无论我在 PostMan 请求 header 中使用什么 ContentType

任何帮助表示赞赏。 谢谢

'Request' 是一个.Net object - 在返回之前转换为字符串类型,如 text/json/html。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM