如何从 .asmx 页面中调用基于 SOAP 的 Web 服务?
我正在尝试使用经典的 .net C# .asmx 页面而不是 WCF 创建一种“引导”Web 服务。 (这个项目的业务需求比较具体,不需要WCF服务)。
基本上,我正在尝试这样做:
- 创建一个新的 Web 服务(这样做没有问题)
- 该服务需要对 Sharepoint Web 服务进行基于 SOAP 的调用
- 我需要使用该服务
- 我需要添加其他信息对于我的 Web 服务到 SOAP 结果(这里也没有问题)
我遇到的问题是第 2 点和第 3 点。我发现很多文章使用 WCF 来使用基于 SOAP 的 Web 服务或使用“Linq”连接到共享点等,但这不是我想要的。
我所寻找的只是我需要做的一步一步的过程,以推动我朝着正确的方向前进。
示例:
- 添加 Web 服务引用?
- 添加这行代码来创建新的 SOAP 请求?
- 添加这行代码来解析和使用服务?
提前非常感谢!
示例代码也将不胜感激!
I am trying to create a sort of "bootstrap" web service using a classic .net C# .asmx page and not WCF. (The business requirements for this project are specific and do not want a WCF service).
Basically, I am trying to do this:
- Create a new web service (I have no problem doing this)
- That service needs to make a SOAP based call to a Sharepoint Web Service
- I need to consume that service
- I need to add additional pieces of information for my web service to the SOAP result (No problem here either)
The issue I have having is with point #2 and #3. I have found plenty of articles using WCF to consume SOAP based Web Services or using "Linq" to connect to sharepoint etc., but that's not what I'm looking for.
What I am looking for is simply a step by step process of what I need to do to push me in the right direction.
Example:
- add a web service reference??
- add this line(s) of code to create a new SOAP request??
- add this line(s) of code to parse and consume the service??
Thank you very much in advance!!!
Sample code would be greatly appreciated as well!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它是一项网络服务,这一事实并没有什么神奇之处。只需使用“添加服务引用”,然后将其视为引用 Web 服务的任何其他代码片段即可。
另外,编写需求的人是否意识到 WCF 服务可以公开看起来与 ASMX Web 服务端点完全相同的
basicHttpBinding
端点?除了不使用 Microsoft 认为的“遗留技术”之外,它还可以享受 WCF 的所有功能。There's nothing magical about the fact that it's a web service. Just use "Add Service Reference" and then treat it like any other piece of code referencing a web service.
Also, are those who wrote the requirements aware that a WCF service can expose a
basicHttpBinding
endpoint that looks exactly like an ASMX web service endpoint? It would also have the benefit of all of the features of WCF, in addition to not using what Microsoft considers a "legacy technology".MSDN 上的 SharePoint 开发人员中心 是一个值得参考的好地方一般信息、教程等。服务器和站点体系结构: Windows SharePoint Services 3 SDK 中的对象模型概述将是开始学习 SharePoint 对象模型的好地方,因为您在示例中遇到的术语(SPSite、SPWeb 等)可能会令人困惑。
基本上,您需要将 Web 引用添加到您想要使用的 SharePoint Web 服务。您使用的具体参考取决于您想要完成的任务,有 可用的 Windows SharePoint Services Web 服务的完整列表。这些用于一般的 SharePoint 任务,例如与列表和网站交互;还有一整套独立的 SharePoint Server Web 服务,您可以使用它与业务数据目录、企业搜索以及 SharePoint Server(而不是 Windows SharePoint Services)附带的任何其他功能进行交互。
当您在 Visual Studio 中添加 Web 引用时,它将自动在您的项目中针对远程 Web 服务生成代理,并且您可以使用生成的代理来执行您想要执行的操作。然而,直接针对 Web 服务工作,几乎所有内容都会返回您必须处理的通用
XmlNode
,因此,如果您在 .NET 中工作,那么有一个比使用Web 服务直接下载 SharePoint SDK 并针对服务器对象模型进行编程。如果您最终使用了对象模型,请确保您彻底阅读了这两部分内容:
最佳实践:使用 SharePoint 对象模型时的常见编码问题
最佳实践:使用一次性 Windows SharePoint Services 对象
The SharePoint Developer Center at MSDN would be a good place to refer to for general information, tutorials, etc. Server and Site Architecture: Object Model Overview in the Windows SharePoint Services 3 SDK would be a good place to start learning about the SharePoint object model, as the terms (SPSite, SPWeb, etc.) that you'll come across in examples can be confusing.
Basically you will want to add your web reference to the SharePoint web service that you intend to use. The specific reference that you use will depend on what you're trying to accomplish, there's a whole list of available Windows SharePoint Services Web Services. Those are for general SharePoint tasks such as interacting with lists and sites; there's also a whole separate set of web services for SharePoint Server which is what you would use for interacting with the Business Data Catalog, Enterprise Search, and any of the other features that come with SharePoint Server, not Windows SharePoint Services.
When you add the web reference in visual studio, it will automatically generate the proxy in your project against the remote web service and you use the generated proxy to do what you want to do. However, working directly against the web services, pretty much everything will return a generic
XmlNode
that you'll have to deal with, so if you're working in .NET, a much better alternative to using the web services directly would be to download the SharePoint SDK and program against the server object model.If you do end up using the object model, make sure you read both of these thoroughly:
Best Practices: Common Coding Issues When Using the SharePoint Object Model
Best Practices: Using Disposable Windows SharePoint Services Objects
这是关于您想要执行的操作的小教程:
http://www.xefteri.com/articles/show.cfm?id=15
Here is small tutorial on what you're trying to do:
http://www.xefteri.com/articles/show.cfm?id=15