可以通过 url 查询字符串使用参数调用 ASMX 服务吗?
我有一个带有单个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以装饰您的方法以允许 HTTP GET 请求,这应该依次执行您要查找的操作,如下所示:
并编辑 web.config :
然后您将能够像这样调用此方法:
http://mysite.com/Service.asmx/MyNiftyMethod?myint=12345
编辑:请注意,这种执行 GET 请求的方法确实带有一些安全风险。根据 UseHttpGet 的 MSDN 文档:
You can decorate your method to allow HTTP GET requests, which should in turn do what you're looking for like so:
And edit the web.config :
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:
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.