我如何发送的ASP.NET Web服务的参数 [英] How can I send parameters for ASP.NET webservice
问题描述
我有一个大学项目,我应该实现一个Java驱动的网站使用Web服务:一些将Servlet和其他人应该.NET的servlet创建创建。我创建了Java servlet,它可以被称为/ login服务/用户名= _ __ &放大器; MD5 = 的__ _ __ 。都好。
现在我必须实现.NET其他服务。我创建了一个ASP.NET Web服务应用程序,但这种类型的应用程序使用POST而不是GET的。我发现,这可以通过添加
I have an university project where I should implement a java powered website that uses web services: some that will be created as servlets and others that should be created as .NET "servlets". I created the java servlet that can be called as /loginservice/username="___"&md5="_____". All good. Now I must implement another service in .NET. I created a ASP.NET web service application but this type of application uses POST instead of GET. I found out that this could be changed by adding
[ScriptMethod(UseHttpGet=true)]
但问题是,像我在Java中做,我不能传递参数。
没有使用POST的任何地方,因为我不希望重写的Java代码的方式。
but the problem is that I can't pass parameters like I do in Java. There is no way of using POST anywhere because I don't want to rewrite the code in 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;
}
}
}
下面是在C#
代码如果我使用的浏览器和手动插入值,一切正常。
Here is the code in C# If I use the browser and manually insert the values all is ok.
但我不能使用GET约定。
预先感谢您。
But I can't use the GET convention. Thank you in advance.
推荐答案
我终于卸下解决问题。
[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中
to Web.config
现在我可以通过调用服务
Now I can call the service using
http://localhost:2586/Service1.asm/HelloWorld?parameter1=abc¶meter2=cde
这篇关于我如何发送的ASP.NET Web服务的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!