使用 ServiceStack 访问 SOAP 网络服务 [英] Access SOAP webservice with ServiceStack

查看:37
本文介绍了使用 ServiceStack 访问 SOAP 网络服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建与 ServiceStack 互通的客户端/服务器应用程序,并且运行良好,但我还需要访问外部 SOAP 网络服务.

I'm creating my client/server application intercommunication with ServiceStack, and is working great, but I need also to access an external SOAP web service.

我尝试使用 Soap12ServiceClient 来访问它,但找不到任何示例,然后我采用了实际有效的添加服务引用 WCF 方式,但创建了大量代码.

I tried to use the Soap12ServiceClient to access it, but I couldn't find any example, and then I went the add service reference WCF way that actually worked, but creating a ton of code.

是否可以像使用 JsonServiceClient 一样简单地使用 Soap12ServiceClient 发送消息/请求并接收消息/响应?如果是这样,你能帮我或给我指一个样本吗?

Is it possible to use Soap12ServiceClient in the same easy way I use JsonServiceClient to send a message/request and receive the message/response? If so, can you help or point me to a sample?

推荐答案

我不知道你遇到了什么ServiceStack 的 C# 服务客户端 实现了相同的 IServiceClient,因此它们可以以相同的方式使用.以下是所有 ServiceStack 内置 C# 服务客户端的示例 调用相同的 Hello World 服务:

I'm not sure where you're stuck as all of ServiceStack's C# Service Clients implement the same IServiceClient so they can be used in the same way. Here is an example of all of ServiceStack's built-in C# Service Clients calling the same Hello World service:

[TestFixture]
public class HelloWorldServiceClientTests
{
    public static IEnumerable ServiceClients
    {
        get
        {
            return new IServiceClient[] {
                new JsonServiceClient(Config.ServiceStackBaseUri),
                new JsvServiceClient(Config.ServiceStackBaseUri),
                new XmlServiceClient(Config.ServiceStackBaseUri),
                new Soap11ServiceClient(Config.ServiceStackBaseUri),
                new Soap12ServiceClient(Config.ServiceStackBaseUri)
            };
        }
    }

    [Test, TestCaseSource("ServiceClients")]
    public void HelloWorld_with_Sync_ServiceClients(IServiceClient client)
    {
        var response = client.Send<HelloResponse>(new Hello { Name = "World!" });

        Assert.That(response.Result, Is.EqualTo("Hello, World!"));
    }
}

虽然 SOAP 的工作方式与任何其他 C# 客户端类似,但以这种方式使用它并不常见,因为如果您能够使用通用 C# SOAP 服务客户端,您也可能能够使用任何其他服务客户端都比 SOAP 更快、更有弹性、更可版本化——除了它能够生成你说你不想做的客户端代理之外,它实际上没有比其他格式更好的质量.

Although SOAP works similar to any other C# client, it's un-common to use it in this way because if you're able to use a generic C# SOAP service client you're also likely able to use any of the other service clients which are all faster, more resilient and more versionable than SOAP - which has effectively has no redeeming quality over the other formats other than its ability to generate client proxies which you said you don't want to do anyway.

如果您不确定应该使用哪种端点或格式,我推荐阅读我对 InfoQ 的采访 讨论了 SOAP 的缺点以及使用其他格式的好处.

If you're undecided which endpoint or format you should use I recommend reading my Interview on InfoQ which discusses the disadvantages of SOAP and the benefits of using the other formats.

这篇关于使用 ServiceStack 访问 SOAP 网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆