如何发送 ASP.NET Web 服务的参数

2023-12-25

我有一个大学项目,我应该在其中实现一个使用 Web 服务的 java 驱动的网站:一些将创建为 servlet,另一些则应创建为 .NET“servlet”。我创建了可以称为 /loginservice/username="__________"&md5="____________" 的 java servlet。都好。 现在我必须在 .NET 中实现另一个服务。我创建了一个 ASP.NET Web 服务应用程序,但此类应用程序使用 POST 而不是 GET。我发现这可以通过添加来改变

[ScriptMethod(UseHttpGet=true)]

但问题是我不能像在Java中那样传递参数。 没有办法在任何地方使用 POST,因为我不想用 Java 重写代码。

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

namespace t5_services
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
   // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet=true)]
        public string Package(String packagename, String lastname)
        {
            return "Hello " + packagename + ": " + lastname;
        }

    }
}

Here is the code in C# If I use the browser and manually insert the values all is ok.

但我不能使用 GET 约定。 先感谢您。


我最终通过删除解决了问题

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

并添加

<webServices>
     <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
     </protocols>
</webServices>

到 Web.config

现在我可以使用调用该服务

http://localhost:2586/Service1.asm/HelloWorld?parameter1=abc&parameter2=cde
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何发送 ASP.NET Web 服务的参数 的相关文章

随机推荐