简体   繁体   English

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

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

I created a really simple webservice using C#我使用 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;
        }
    }
}

I am using Postman to test.我正在使用 Postman 进行测试。

The HelloWorld() works OK HelloWorld() 工作正常

The Mirror() returns error: Mirror() 返回错误:

System.InvalidOperationException: Request format is invalid: text/plain. System.InvalidOperationException:请求格式无效:文本/纯文本。 at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()在 System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

whatever the ContentType I use in the PostMan Request header无论我在 PostMan 请求 header 中使用什么 ContentType

Any help appreciated.任何帮助表示赞赏。 Thank you谢谢

'Request' is a.Net object - convert to a string type like text/json/html before returning. 'Request' 是一个.Net object - 在返回之前转换为字符串类型,如 text/json/html。

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

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