可以通过 url 查询字符串使用参数调用 ASMX 服务吗?

发布于 2024-08-17 01:08:06 字数 387 浏览 1 评论 0原文

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

有没有办法直接从 URL/查询字符串调用 Web 服务?

这不起作用:

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

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

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.

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

This doesnt work:

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤感在游骋 2024-08-24 01:08:06

您可以装饰您的方法以允许 HTTP GET 请求,这应该依次执行您要查找的操作,如下所示:

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

并编辑 web.config :

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

然后您将能够像这样调用此方法:

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

编辑:请注意,这种执行 GET 请求的方法确实带有一些安全风险。根据 UseHttpGet 的 MSDN 文档:

UseHttpGet 属性设置为
true 可能会带来安全风险
如果您在工作,您的申请
敏感数据或交易。
在 GET 请求中,消息是
由浏览器编码到 URL 中
因此是一个更容易的目标
篡改。

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
}

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

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

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.

音栖息无 2024-08-24 01:08:06

ASMX Web 服务使用 SOAP。 SOAP 请求仅使用 POST 来调用方法。您需要在您的 aspx 页面中生成一个代理客户端来调用 Web 服务。如果您确实需要使用 GET 动词来调用 Web 服务,您可能需要使用不同的方法,例如 WCF 休息

ASMX web services use SOAP. SOAP requests use only POST to invoke methods. You will need to generate a proxy client in your aspx page to invoke the web service. If you really need to use GET verbs to invoke web services you might need to use a different approach such as WCF REST.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文