【问题标题】:Delphi 7 and WCF. Complex type problem德尔福 7 和 WCF。复杂类型问题
【发布时间】:2011-09-26 11:59:17
【问题描述】:

我有一个基于 basicHTTPBinding 的 WCF 服务。我从 Delphi 7 和 .NET 表单中调用此服务。 D7 客户端能够成功调用具有原始输入和输出类型的操作。但是,当调用具有复杂类型的操作时,Web 服务会将复杂类型接收为 NULL。 .Net 客户端工作正常。这是从 Fiddler 检索到的请求标头。

德尔福客户端

<?xml version="1.0"?>
<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">

<SOAP-ENV:Body>

<GetDataUsingDataContract xmlns="http://tempuri.org/">

<composite xmlns="http://schemas.datacontract.org/2004/07/DelphiService2">

<BoolValue>true</BoolValue>

<StringValue>Test</StringValue>

</composite>

</GetDataUsingDataContract>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

.Net 客户端

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>

<GetDataUsingDataContract xmlns="http://tempuri.org/">

<composite xmlns:a="http://schemas.datacontract.org/2004/07/DelphiService2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

<a:BoolValue>true</a:BoolValue>
<a:StringValue>test</a:StringValue>

</composite>

</GetDataUsingDataContract>

</s:Body>

</s:Envelope>

【问题讨论】:

    标签: wcf delphi delphi-7


    【解决方案1】:

    您的问题是由 Delphi 客户端将定义的复合元素放在“http://tempuri.org/”XML 命名空间而不是“http://schemas.datacontract. org/2004/07/DelphiService2" 命名空间。复合、BoolValue 和 StringValue 元素都需要在“http://schemas.datacontract.org/2004/07/DelphiService2”XML 命名空间中定义(在这种情况下以命名空间别名“a:”为前缀)。

    如果无法调整 Delphi 客户端序列化程序,解决此问题的一种方法是替换 WCF 提供的默认命名空间“http://tempuri.org/”和“http://schemas.datacontract.org/” 2004/07/DelphiService2" 与您自己定义的一个。调整服务契约以符合 changes outlined in this post 并更改 DataContracts 以匹配新的 XML 命名空间。这样,所有服务定义的操作和对象都将位于同一个 XML 命名空间中。

    [DataContract(Namespace="http://YourNamespace/2011/09/DelphiService2")]
    public class composite
    {
        public bool BoolValue {get; set;}
        public string StringValue {get; set;}
    }
    

    【讨论】:

      猜你喜欢
      • 2014-07-08
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      • 2018-03-05
      • 2020-04-24
      • 1970-01-01
      相关资源
      最近更新 更多