在 VB.NET 中使用 Web 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2297419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Consuming web services in VB.NET
提问by tpow
I am testing web services in .NET for the first time. I am almost there, but I can't seem to consume the web service. I know this post is similar to about 5-6 other posts on this site, but I have reviewed them, and still can't get the syntax correct.
我第一次在 .NET 中测试 Web 服务。我快到了,但我似乎无法使用 Web 服务。我知道这篇文章与本网站上大约 5-6 篇其他文章类似,但我已经查看了它们,但仍然无法获得正确的语法。
So far, I have: -Create a simple web service that creates a directory -Worked in development environment, but took some trouble shooting to get to work on live server -I can pull up the "automagically" generated .NET we service page. -Added web service reference - can now see the reference in my solution explorer and in intellisense.
到目前为止,我已经: - 创建一个简单的 web 服务,创建一个目录 - 在开发环境中工作,但在实时服务器上工作时遇到了一些麻烦 - 我可以拉出“自动”生成的 .NET 我们服务页面。- 添加了 Web 服务参考 - 现在可以在我的解决方案资源管理器和智能感知中看到参考。
Update: Here is a link to the webservice itself: http://67.78.188.50/Jservices/Service1.asmx
更新:这里是网络服务本身的链接:http: //67.78.188.50/Jservices/Service1.asmx
The web service accepts a string (name of directory e.g /test/directory). However, when I enter the name of the Web Reference (ServiceReference1) - I don't get the methods I expect...
Web 服务接受一个字符串(目录名称,例如 /test/directory)。但是,当我输入 Web 引用 (ServiceReference1) 的名称时 - 我没有得到我期望的方法......
Here are my options with the ServiceReference1 Object...
这是我对 ServiceReference1 对象的选项...
ServiceReference1.makeDirRequest
ServiceReference1.makeDirRequestBody
ServiceReference1.makeDirResponse
ServiceReference1.makeDirResponseBody
ServiceReference1.Service1Soap
ServiceReference1.Service1SoapChannel
ServiceReference1.Service1SoapClient
回答by TFD
Pass, you haven't posted enough code to see what you have done
通过,你还没有发布足够的代码来看看你做了什么
I would strongly recommend that your use WCF
我强烈建议您使用 WCF
Given your sample names proved, you need
鉴于您的样本名称已证明,您需要
Dim service As New ServiceReference1.Service1SoapClient
service.makeDir("some val")
Download one of the many samples on the web (plenty on codeproject) and get the sample working first. If you cant get that to go then something else is wrong with you Windows installation
下载 Web 上的众多示例之一(在codeproject上有很多),然后先让示例工作。如果你不能让它去,那么你的 Windows 安装有其他问题
回答by Marc Gravell
I'm not sure that makeDirRequestis the service - that sounds like a message. Look for another type in that namespace (maybe ending in "service" or "client" if you are lucky, but ultimately named based on what you typed when using "add web reference" etc), that inherits from WebService.
我不确定那makeDirRequest是服务——这听起来像是一条消息。在该命名空间中查找另一种类型(如果幸运的话,可能以“service”或“client”结尾,但最终根据您在使用“add web reference”等时键入的内容命名),它继承自WebService.
Thisshould have your servicemethod(s) as public methods.
这应该将您的服务方法作为公共方法。
Having seen the service, I expectthe problem is that you are adding a service-reference(WCF / 3.0) rather than a web-reference(2.0). If you are targetting 3.0 / 3.5, you can add a web-referenceby using the "Advanced..." => "Add Web Reference" option
(in the "Add Service Reference" dialog). Then you can use (where WebReferenceis whatever you named it when adding the reference):
看过该服务后,我预计问题在于您添加的是服务引用(WCF / 3.0) 而不是Web 引用(2.0)。如果您靶向3.0 / 3.5,您可以添加一个网络参考使用“高级...” =>“添加Web引用”选项(在“添加服务引用”对话框)。然后你可以使用(WebReference添加引用时你命名的任何内容):
Using client As WebReference.Service1 = New WebReference.Service1
Dim foo As String = "foo"
client.makeDir(foo)
End Using
If you instead use a WCF service-reference, then the name tends to include the "Soap" overhead (where ServiceReference1is whatever you named it when adding the reference):
如果您改为使用WCF service-reference,则该名称往往包含“Soap”开销(ServiceReference1添加引用时您命名的任何内容):
Using client As ServiceReference1.Service1SoapClient = New ServiceReference1.Service1SoapClient
Dim foo As String = "foo"
client.makeDir(foo)
End Using
Either way, it should work the same.
无论哪种方式,它都应该工作相同。
回答by ratty
Consume a Web service in a .NET app
在 .NET 应用程序中使用 Web 服务
http://articles.techrepublic.com/5100-10878_11-5768122.html
http://articles.techrepublic.com/5100-10878_11-5768122.html
Creating and Consuming Web Services - OS, Software & Networking by ...
创建和使用 Web 服务 - 操作系统、软件和网络...
http://www.extremetech.com/article2/0,2845,11511,00.asp
http://www.extremetech.com/article2/0,2845,11511,00.asp
Consuming Web Services from a Win Forms Application - CodeProject
从 Win Forms 应用程序使用 Web 服务 - CodeProject
http://www.codeproject.com/KB/webservices/cpwebserviceconsumer.aspx
http://www.codeproject.com/KB/webservices/cpwebserviceconsumer.aspx
回答by John Saunders
See How to Consume a Web Serviceand see if it helps you. The example is in C#, but you should find it easy to translate.
请参阅如何使用 Web 服务,看看它是否对您有帮助。该示例是用 C# 编写的,但您应该会发现它很容易翻译。

