【问题标题】:WCF Delphi7 method input parametersWCF Delphi7方法输入参数
【发布时间】:2026-02-10 01:25:01
【问题描述】:

我有 wcf web-service(basicHttpBinding)。我们的 Delphi7 客户无法正确使用它。 我已经用 WCF 附加功能将 WSDL 扁平化了。好的。 Delphi7 wsdl importer 生成代理正确。

现在我遇到了输入参数的问题。它们总是有默认值(字符串为空,int 为 0)。

delphi7 方法的输出值正常。 例如:

        public string Test(string a)
        {
              return "Test"+a;
        }

此方法总是返回“Test”。我的日志系统修复了我的 at 方法为空,所以问题是正确的传输输入参数。

我不明白怎么了

编辑

代理:

ISyncer = interface(IInvokable)
  ['{D46862B0-BDD3-8B80-35A8-A2AC69F24713}']
    function  Test(const a: String): String; stdcall;
  end;

呼叫:

Sync:=(dmMain.HTTPRIO1 as ISyncer);
test:=Sync.Test('5555');

dmMain.HTTPRIO1 在选项中有 soLiteralParams:

初始化:

InvRegistry.RegisterInvokeOptions(TypeInfo(ISyncer), ioLiteral);

通话后我收到异常消息:

Error deserializtion message body for operation Test. 
Operation formatter detects ivalid message body. Expecting node type "Element"
with name "Test" and namespace "http://tempuri.org". Actually node type "Element"
with name "xsd:String" and namespace "http://w3.org/2001/XMLSchema"

wsdl 片段:

<xsd:element name="Test">
−
<xsd:complexType>
−
<xsd:sequence>
<xsd:element minOccurs="0" name="a" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
−
<xsd:element name="TestResponse">
−
<xsd:complexType>
−
<xsd:sequence>
<xsd:element minOccurs="0" name="TestResult" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

EDIT2

我研究 http 请求:

.NET

<Test> xmlns="http://tempuri.org/"><a>5555</a></Test>

工作正常;

Delph7

<Test xmlns="http://tempuri.org/"><xsd:a>5555</xsd:a></Test>

空输入参数。 问题出在前缀 xsd

【问题讨论】:

  • 不确定是什么原因。你有任何例外吗?此服务是否适用于 .net 客户端(测试目的)?
  • 没有例外,服务在 .net 客户端上运行良好。输入参数正确传递
  • 请发布wsdl和生成的代理类
  • 大约 2 年前,我试图让 Web 服务在 .NET 和 Delphi 7 之间工作,但发现它非常困难。就像下面的 Darin 所说,这些问题与 SOAP 样式有关,最终存在无法解决的差异(我记得数组和自定义类是一场噩梦)。我希望我能为您提供更多详细信息,但我最终只是手动定义了通过发布数据来回传递的消息。如果您有另一种可能的解决方法(我浪费了一周),您可能不想在此上花费太多时间。祝你好运!
  • o6tech,感谢您的回答。我不需要数组、自定义类,只需要原始类型(int、string)。我不想回到 asmx(它与 delphi7 完美配合)。我非常想以 wcf 的方式来做 :)

标签: .net wcf web-services delphi wsdl


【解决方案1】:

Delphi 使用 RPC/Encoded SOAP,而 WCF 使用 Document/Literal/Wrapped SOAP。所以你需要告诉 Delphi 使用相同的格式。您可以通过在 THttpRio.Converter.Options 中指定 soLiteralParams 来做到这一点。

【讨论】:

  • @Darin:您能否在 THTTPRIO.converter.Options 中发布指定 solietralPrams 的代码声明?
【解决方案2】:

我已经做到了。 我通过 THttpRio 的事件处理程序 OnBeforeExecute 为每个服务对象修复了肥皂信封。

我修复(删除命名空间前缀)并且它有效。 谢谢

【讨论】: