如何在.asmx服务中调用方法 [英] How do I call methods in an .asmx service
问题描述
我正在尝试在创建新的asmx Web服务时调用由visual studio创建的HelloWorld方法。
我已将* .asmx.cs文件添加到测试站点的App_Code文件夹,将.asmx文件添加到站点根目录。如果我去testserver / Service1.asmx,我会看到列出服务方法的页面。
如果我尝试使用testserver / Service1.asmx / HelloWorld,我会收到错误消息。如何运行服务或调用HelloWorld方法。
我花了两天半的时间用谷歌搜索,阅读和观看视频,试图找出我需要做的事情或我做错了什么。
I am trying to call the HelloWorld method that is created by visual studio when you create a new asmx web service.
I have added the *.asmx.cs file to the App_Code folder of the test site and the .asmx file to the sites root. If I go to testserver/Service1.asmx I see the page that list the services methods.
If I try testserver/Service1.asmx/HelloWorld I get an error. How can I get the service running or call the HelloWorld method.
I have spent two and a half days googling, reading and watching videos trying to figure I out what I need to do or what I am doing wrong.
推荐答案
服务正在运行,你只是没有正确访问它。
你可能正在获得一个错误如:对于意外以/ HelloWorld结尾的URL无法识别请求格式。
Web服务(必然)的行为与常规网页不同。例如,当您导航到网页时,您的浏览器正在执行GET
请求。
Hello World Web服务不允许GET
请求。如果您转到http:// localhost:8801 / Service1.asmx?op = HelloWorld
(将端口更改为运行服务的任何端口),您将获得一个页面像这样:
< img src =http://www.codeproject.com/script/Membership/Uploads/1740717/Screenshot_2014-06-12_12.01.53 .pngwidth =600/>
它向您展示了三种与Web服务交互的不同方式。
如果单击调用
按钮,浏览器将执行POST
请求,这是什么Web服务期待。
我建议使用 Fiddler [ ^ ]构建可以发送到Web服务器的查询,并看到原始响应。
The service is running, you're just not accessing it correctly.
You're probably getting an error like: Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.
Web services don't (necessarily) behave like regular web pages do. For example, when you navigate to a web page your browser is performing aGET
request.
The Hello World web service goes not allowGET
requests. If you go tohttp://localhost:8801/Service1.asmx?op=HelloWorld
(change the port to whatever port your service is running on) you will get a page like this:
<img src="http://www.codeproject.com/script/Membership/Uploads/1740717/Screenshot_2014-06-12_12.01.53.png" width="600" />
It shows you three different ways to interact with your web service.
If you click theInvoke
button, your browser will perform aPOST
request, which is what the web service is expecting.
I recommend using Fiddler[^] to construct queries that you can send to a web server, and see the raw response.
这篇关于如何在.asmx服务中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!