Web 服务/WCF 新手:针对基于 Java 的 SOAP Web 服务创建 WCF 代理客户端/对象
我有一个 .Net Web 应用程序,需要通过 SOAP 与基于 Java 的系统进行交互。
除了一些基本的 WCF 之外,我没有使用过 Web 服务,并且希望得到任何有关这方面的指导。
基本上,我正在考虑创建一个 WCF 代理客户端来连接到 SOAP Web 服务。该系统是一个基于Java 的第三方系统,提供SOAP 接口。
提供的示例代码使用wsdl来生成代理,但这不是在WCF时代之前吗?
UsernameToken aToken = new UsernameToken("root", "root", PasswordOption.SendPlainText);
MetadataService.MetadataService aMetadataService = new MetadataService.MetadataService();
SoapContext aContext = aMetadataService.RequestSoapContext;
aContext.Security.Tokens.Add(aToken);
String aXmp = aMetadataService.s_getXmpFromRecordID(wAssetId.Text);
有什么建议吗? 谢谢你!
I have a .Net web application that needs to interact with a Java-based system via SOAP.
I have not worked with web services other than some basic WCF and would appreciate any guidance on this.
Basically, I was thinking about creating a WCF proxy client to connect to the SOAP web services. The system is a 3rd party Java-based system that provides a SOAP interface.
The sample code provided used wsdl to generate the proxy, but isn't that before the times of WCF?
UsernameToken aToken = new UsernameToken("root", "root", PasswordOption.SendPlainText);
MetadataService.MetadataService aMetadataService = new MetadataService.MetadataService();
SoapContext aContext = aMetadataService.RequestSoapContext;
aContext.Security.Tokens.Add(aToken);
String aXmp = aMetadataService.s_getXmpFromRecordID(wAssetId.Text);
Any suggestions?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WSDL 是您为 Web 服务生成客户端代理所需的全部内容。不,这不是 WCF 时代之前的情况。 WSDL 是专门为此目的而设计的。
最简单的解决方案是使用 svcutil 创建代码。
您使用 Web 服务的 WSDL 调用 svcutil,然后返回客户端代码及其配置。
然后,您可以将 Web 服务的操作作为客户端实例上的方法进行调用。就这么简单!
例如,让我们考虑这样一个基本的 Web 服务: http://www.startvbdotnet.com/ web/sample2.asmx (这是我通过 google 找到的作为网络服务公开的基本数学)。
要为此生成客户端,我将使用 svcutil,如下所示:
此命令将生成
Sample.cs
和output.config
文件(客户端的代码和配置)。您将这些添加到您的项目中(以及所需的程序集,例如
System.ServiceModel
和System.Runtime.Serialization
),现在您可以使用如下代码调用 Web 服务:WCF 让事情变得简单。通过在服务类上使用正确的配置或属性,添加安全性也很简单。
The WSDL is all you need to generate a client proxy for the web service. And no, this is not before the times of WCF. WSDL was designed specifically for this purpose.
The simplest solution is to use svcutil to create the code.
You call svcutil with the WSDL of the web service and you get back the client code along with the configuration for it.
You then call the operations of the web service as methods on the client instance. It's as simple as that!
For example, lets consider a basic web service like this one: http://www.startvbdotnet.com/web/sample2.asmx (it's basic math exposed as a web service which I found by google-ing).
To generate a client for this I would use svcutil like so:
This command will generate the
Sample.cs
andoutput.config
files (the code and configuration for the client).You add these to your project (along with needed assemblies like
System.ServiceModel
andSystem.Runtime.Serialization
) and now you can call the web service with code like this one:WCF makes things easy. Adding security is also simple with use of proper configuration or attributes on the service classes.