可以通过网址查询字符串调用带参数的ASMX服务吗? [英] Possible to invoke ASMX service with parameter via url query string?

查看:72
本文介绍了可以通过网址查询字符串调用带参数的ASMX服务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个采用单个int参数的asmx服务.我可以打开服务的URL,然后看到服务描述屏幕.从这里,我可以将查询参数输入表单并调用Web服务.

I've got a asmx service that takes a single int parameter. I can open the URL to the service and see the service description screen. From here I can enter the query parameters into a form and invoke the web service.

有什么方法可以直接从URL/查询字符串直接调用Web服务?

Is there any way to invoke a web service directly from a URL/query string?

这不起作用:

http://localhost:4653/MyService.asmx?op = MyWebMethod& intParameter = 1

有什么想法吗?由于某些部署问题,我真的很希望能够从标准链接执行此操作.我是否必须将请求包装在普通的aspx页面中?

Any ideas? I'd really like to be able to do this from a standard link due to some deployment issues. Am I going to have to wrap the request in a normal aspx page?

推荐答案

您可以修饰您的方法以允许HTTP GET请求,依次执行以下操作:

You can decorate your method to allow HTTP GET requests, which should in turn do what you're looking for like so:

[WebMethod]  
[ScriptMethod(UseHttpGet=true)]
public string MyNiftyMethod(int myint)
{
    // ... code here
}

并编辑web.config:

And edit the web.config :

<system.web>
<webServices>
  <protocols>
    <add name="HttpGet"/>
  </protocols>

然后,您将可以像下面这样调用此方法:

Then you'll be able to call this method like so:

http://mysite.com/Service.asmx/MyNiftyMethod?myint=12345

请注意,执行GET请求的这种方法确实存在一些安全风险.根据 UseHttpGet的MSDN文档:

Note that this method of performing GET requests does come with some security risks. According to the MSDN documentation for UseHttpGet:

UseHttpGet 属性设置为 true 可能会对 您的应用程序(如果正在工作) 处理敏感数据或交易. 在GET请求中,该消息是 由浏览器编码到URL中 因此是更容易实现的目标 篡改.

Setting the UseHttpGet property to true might pose a security risk for your application if you are working with sensitive data or transactions. In GET requests, the message is encoded by the browser into the URL and is therefore an easier target for tampering.

这篇关于可以通过网址查询字符串调用带参数的ASMX服务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆