在ServiceStack中使用wsdl soap服务 [英] Consuming wsdl soap service with servicestack

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

问题描述

我一直在尝试通过asp.net C#mvc5应用程序使用wsdl soap服务.最初的服务是用php编写的,理想情况下应该没有关系,但我无法进行这项工作.我刚刚了解到,服务堆栈是一种与mvc架构配合使用的替代方法.我正在寻找有关如何通过servicestack消耗wsdl soap服务的指针,对此将有所帮助.我很乐意购买能够指导我如何在我的mvc应用程序中使用这两种方法的书

I have been trying to consume wsdl soap service with asp.net C# mvc5 application. The original service is written in php which should ideally not matter but I have not been able to make this work. I have just learnt that servicestack is an alternative that works well with mvc architecture. I am looking for pointers on how to consume wsdl soap service with servicestack any help on this will be appreciated. I am happy to buy books that will guide me on how to any of these two methods will work with my mvc application

推荐答案

ServiceStack通过自动为

ServiceStack allows your .NET Services to be exposed via SOAP endpoints by automatically generating WSDL's and XSD's for SOAP Compatible Services which can be consumed with either the generated client proxy created with VS .NET's Add Service Reference or with ServiceStack's .NET Soap11ServiceClient and Soap12ServiceClient.

但是ServiceStack没有提供用于使用任何第三方SOAP服务的通用SOAP客户端. SOAP是不必要的复杂而脆弱的格式,您最好的选择是询问PHP开发人员SOAP服务(如果他们可以推荐任何.NET SOAP客户端的话),因为除非经过测试和验证它们是否兼容,否则任何独立的SOAP客户端实现都不太可能互操作,而不会出现问题.

But ServiceStack doesn't provide a general purpose SOAP client for consuming any 3rd party SOAP Services. SOAP's an unnecessarily complex and brittle format where your best option is to ask the developers of the PHP SOAP Service if they can recommend any .NET SOAP clients since it's unlikely any independent SOAP client implementations will be interoperable without issues unless they've been tested and verified as compatible.

最不可靠的选择是在构造原始SOAP请求并将其发布到远程端点(例如SOAP 1.1 Request)时将SOAP XML视为字符串,

Failing that the most reliable option is to treat the SOAP XML as a string where you construct a raw SOAP Request and POST it to the remote endpoint, e.g SOAP 1.1 Request:

var soapRequest = @"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>"
  + requestXml 
  + "</soap:Body></soap:Envelope>";

使用 HTTP Utils

var soapResponseXml = soapEndpointUrl.PostXmlToUrl(soapRequest, 
  httpReq => httpReq.Headers["SOAPAction"] = requestName);

然后使用WCF的 Message.CreateMessage(),即使WCF通用消息也不支持SOAP响应,您也可以尝试使用

Then parse the SOAP Response with WCF's Message.CreateMessage(), if even WCF generic Message doesn't support the SOAP Response you can try to parse it dynamically as XML using something like XLINQ's XDocument.

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

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