Delphi 7和WCF.复杂类型问题



我有一个基于basicHTTPBinding的WCF服务。我调用这个服务从Delphi 7和。net的形式。D7客户机能够成功地调用具有基本输入和输出类型的Operation。但是,当调用复杂类型的操作时,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>

。网络客户端

<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>

您的问题是由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/"one_answers"http://schemas.datacontract.org/2004/07/DelphiService2"替换为您自己定义的名称空间。调整服务契约以符合本文中概述的更改,并更改DataContracts以匹配新的XML名称空间。这样,所有服务定义的操作和对象都将在同一个XML命名空间中。

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

最新更新