ASP.NET - 使用 SOAP 调用 Web 服务
我从事 .NET 和 C# 编程已经有一段时间了,但这是我第一次尝试用它来做任何基于 Web 的事情。我需要调用一个 SOAP Web 服务(我知道该服务的 URL),并调用该服务的方法。我已在我的项目中将其设置为“Web 参考”,但是,我现在不确定如何调用该服务的方法。在过去的一个小时里,我一直在谷歌上搜索这个问题,试图找出我需要做什么,但根据我看到的结果,这是一件很难/复杂的事情(我知道这不是真的)!
任何人都可以向我展示一些直接的示例代码,用于调用您已设置为 Web 参考的某些通用 Web 服务上的方法,或者向我指出一个不错的教程吗?我认为,考虑到我过去使用 C# 和 .Net 的经验,一旦我能弄清楚这一部分,这个项目就不会成为问题......
提前致谢!
I've been doing .NET and C# programming for quite some time, but this is my first attempt at doing anything web-based with it. I need to call a SOAP web service, which I know the URL for, and call methods of that service. I've set it up as a "Web Reference" in my project, however, I'm now not sure how to call methods of the service. I've been Googling this for the past hour trying to figure out what I need to do, but based on the results I'm seeing, this is a hard/convoluted thing to do (and I know it's not really)!
Can anyone please show me some straight-forward sample code for calling methods on some generic web service that you've got set up as a Web Reference OR point me to a decent tutorial that does? I think, given my experience of using C# and .Net in the past, this project won't be an issue once I can figure this one part out...
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
成功添加 Web 引用后,Visual Studio 生成了一堆包装服务公开的类型和方法的代码。查看这些文件以找出它们所在的命名空间以及实际服务代理类的名称。导入命名空间后,只需创建代理实例并调用其方法即可。
When you added the web reference successfully Visual Studio generated a bunch of code that wraps the types and methods exposed by the service. Look at those files to figure out which namespace they're under, and the name of the actual service proxy class. Once you import the namespace it's just a matter of creating an instance of the proxy and calling its methods.
您将像调用任何对象方法一样调用 Web 服务方法。因为.net框架为你创建了所有必需的类。
添加Web引用时VS IDE会要求输入名称,该名称是访问相关方法名称的根命名空间。
You will call the web services methods just like calling any object method. Because .net framework created all required classes for you.
When adding web reference VS IDE asks for a name, this name is the root namespace to access related method names.