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

查看:32
本文介绍了可以通过 url 查询字符串使用参数调用 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.

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

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