Delphi 7 and WCF. Complex type problem
I have a WCF service based on basicHTTPBinding. I am calling this service from Delphi 7 and .NET form. The D7 client is able to successfully call the Operation that has primitive input and output type. However, when an operation with complex type is called, the web service receives the complex type as NULL. .Net client is working fine. Here hare the Request headers retrieved from Fiddler.
Delphi client
<?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 Client
<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:S开发者_StackOverflow中文版tringValue>test</a:StringValue>
</composite>
</GetDataUsingDataContract>
</s:Body>
</s:Envelope>
Your issue is caused by the Delphi client putting the composite element being defined in the "http://tempuri.org/" XML namespace instead of the "http://schemas.datacontract.org/2004/07/DelphiService2" namespace. The composite, BoolValue & StringValue elements all need to be defined in the "http://schemas.datacontract.org/2004/07/DelphiService2" XML namespace (prefixed with the namespace alias "a:" in this case).
One way to solve this issue if the Delphi client serializer can't be tweaked is to replace the WCF supplied default namespaces of "http://tempuri.org/" and "http://schemas.datacontract.org/2004/07/DelphiService2" with one you define yourself. Tweak the service contract to conform to the changes outlined in this post and also change the DataContracts to match the new XML namespace. This way all the service defined operations and objects will be in the same XML namespace.
[DataContract(Namespace="http://YourNamespace/2011/09/DelphiService2")]
public class composite
{
public bool BoolValue {get; set;}
public string StringValue {get; set;}
}
精彩评论