Web 服务/WCF 新手:针对基于 Java 的 SOAP Web 服务创建 WCF 代理客户端/对象

发布于 2024-12-05 00:49:35 字数 624 浏览 1 评论 0原文

我有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦÷微暖 2024-12-12 00:49:35

WSDL 是您为 Web 服务生成客户端代理所需的全部内容。不,这不是 WCF 时代之前的情况。 WSDL 是专门为此目的而设计的。

最简单的解决方案是使用 svcutil 创建代码。

您使用 Web 服务的 WSDL 调用 svcutil,然后返回客户端代码及其配置。

然后,您可以将 Web 服务的操作作为客户端实例上的方法进行调用。就这么简单!

例如,让我们考虑这样一个基本的 Web 服务: http://www.startvbdotnet.com/ web/sample2.asmx (这是我通过 google 找到的作为网络服务公开的基本数学)。

要为此生成客户端,我将使用 svcutil,如下所示:

svcutil http://www.startvbdotnet.com/web/sample2.asmx?wsdl

此命令将生成 Sample.csoutput.config 文件(客户端的代码和配置)。

您将这些添加到您的项目中(以及所需的程序集,例如 System.ServiceModelSystem.Runtime.Serialization),现在您可以使用如下代码调用 Web 服务:

using (SampleSoapClient proxy = new SampleSoapClient())
{
    Console.WriteLine(proxy.Add(6, 2));
    Console.WriteLine(proxy.Substract(6, 2));
    Console.WriteLine(proxy.Divide(6, 2));
    Console.WriteLine(proxy.Multiply(6, 2));
}

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:

svcutil http://www.startvbdotnet.com/web/sample2.asmx?wsdl

This command will generate the Sample.cs and output.config files (the code and configuration for the client).

You add these to your project (along with needed assemblies like System.ServiceModel and System.Runtime.Serialization) and now you can call the web service with code like this one:

using (SampleSoapClient proxy = new SampleSoapClient())
{
    Console.WriteLine(proxy.Add(6, 2));
    Console.WriteLine(proxy.Substract(6, 2));
    Console.WriteLine(proxy.Divide(6, 2));
    Console.WriteLine(proxy.Multiply(6, 2));
}

WCF makes things easy. Adding security is also simple with use of proper configuration or attributes on the service classes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文