Delphi SOAP 信封和 WCF [英] Delphi SOAP Envelope and WCF

查看:21
本文介绍了Delphi SOAP 信封和 WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个提供肥皂界面的系统.将要使用该接口的系统之一是在 Delphi 7 中编写的.Web 服务是使用 WCF、基本 http 绑定、SOAP 1.1 开发的.

I am working on a system that provides a soap interface. One of the systems that are going to use the interface is coded in Delphi 7. The web service is developed with WCF, basic http binding, SOAP 1.1.

如果我使用 SOAP UI (JAVA),则该服务可以正常工作.但是 Delphi 似乎在这里做了一些特别的事情 ;)

If I use SOAP UI (JAVA), the service works properly. But Delphi seems to do special things here ;)

这是消息在 SOAP UI 中的样子:

This is how the message looks like in SOAP UI:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.xxx.de/xxx">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:GetCustomer>
         <!--Optional:-->
         <ser:GetCustomerRequest> <!-- this is a data contract -->
            <ser:Id>?</ser:Id>
         </ser:GetCustomerRequest>
      </ser:GetCustomer>
   </soapenv:Body>
</soapenv:Envelope>

我不是 delphi 开发人员,但我开发了一个简单的测试客户端来查看出现了什么问题.这是 Delphi 作为 SOAP 信封发送的内容.

I am not a delphi developer , but I developed a simple test client to see what's going wrong. This what Delphi sends as a SOAP envelope.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS2="http://services.xxx.de/xxx">
    <NS1:GetCustomer xmlns:NS1="http://services.xxx.de/xxx">
      <GetCustomerRequest href="#1"/>
    </NS1:GetCustomer>
    <NS2:GetCustomerRequest id="1" xsi:type="NS2:GetCustomerRequest">
      <Id xsi:type="xsd:int">253</Id>
    </NS2:GetCustomerRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

WCF 抛出一个德语错误...;)

WCF throws an error that is in German language... ;)

Es wurde das Endelement "Body" aus Namespace "http://schemas.xmlsoap.org/soap/envelope/" erwartet.Gefunden wurde "元素 "NS2:GetCustomerRequest" aus 命名空间 "http://services.xxx.de/xxx".Zeile 1,位置 599.

Es wurde das Endelement "Body" aus Namespace "http://schemas.xmlsoap.org/soap/envelope/" erwartet. Gefunden wurde "Element "NS2:GetCustomerRequest" aus Namespace "http://services.xxx.de/xxx"". Zeile 1, Position 599.

表示类似

身体是预期的.但是找到了元素NS2:GetCustomerReques".

The Body was expected. But instead the Element "NS2:GetCustomerReques" was found.

现在我的问题是:我能否以某种方式改变 Delphi 创建信封的方式?或者有什么方法可以让 WCF 使用这种消息格式?非常感谢任何帮助!

Now my questions is: Can I somehow change the way Delphi creates the envelope? Or are the ways to make WCF work with such message formats? Any help is greatly appreciated!

推荐答案

与这里某些人似乎暗示的相反,Delphi 没有发送 无效 SOAP,它只是发送 RPC/编码 SOAP.从所有 xsi:type 属性中很容易识别.RPC/Encoded 不符合 WS-I,但它仍然有效的 SOAP.

Contrary to what some people here seem to be implying, Delphi is not sending invalid SOAP, it is simply sending RPC/Encoded SOAP. It's very easy to recognize from all the xsi:type attributes. RPC/Encoded is not WS-I compliant but it is still valid SOAP.

WCF 默认使用Document/Literal/Wrapped SOAP 格式,Delphi 7 在服务器端根本无法处理这种格式,您必须在客户端进行一些调整.

WCF, by default, uses the Document/Literal/Wrapped SOAP format, which Delphi 7 can't handle at all on the server side and you have to make some adjustments on the client side.

最简单的解决方案是简单地告诉 Delphi 使用文档/文字样式.您可以通过在 THttpRio.Converter.Options 中打开 soLiteralParams 来实现.这告诉 Delphi 不要像您看到的那样展开"参数.文档"方面是 Delphi WSDL 导入器通常可以解决的问题,因此您无需担心.

The simplest solution is to simply tell Delphi to use the Document/Literal style. You do that by turning on soLiteralParams in the THttpRio.Converter.Options. This tells Delphi not to "unwind" the parameters as you are seeing. The "Document" aspect is something that the Delphi WSDL importer can usually figure out so you shouldn't need to worry about that.

另一种解决方案是告诉 WCF 服务使用 RPC/Encoded 样式,您可以通过向服务添加以下属性来实现:

The other solution is to tell the WCF service to use RPC/Encoded style, which you can do by adding the following attributes to the service:

[ServiceContract]
[XmlSerializerFormat(Style = OperationFormatStyle.Rpc,
    Use = OperationFormatUse.Encoded)]
public interface IMyService
{
    // etc.
}

不推荐使用第二种方法,因为正如我之前提到的,RPC/Encoded 不符合 WS-I,但尽管如此,大多数 SOAP 工具包都可以识别它,因此我在此处将其列为一种可能性.

The second is not recommended because, as I mentioned earlier, RPC/Encoded is not WS-I compliant, but nevertheless most SOAP toolkits do recognize it, so I list it here as a possibility.

这篇关于Delphi SOAP 信封和 WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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