我希望我的WCF响应有一个带有两个名称空间的响应元素使用DataContracts,但我无法让它工作.这就是我想要的回应:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<s:Header />
<s:Body>
<ns2:TestReply xmlns="http://www.test.org/test/2007/00" xmlns:ns2="http://www.test2.org/test2/types">
<ns2:Result>
<ns2:ActionSuccessful>true</ns2:ActionSuccessful>
</ns2:Result>
<ns2:ResultData>
<ns2:Name>Maikel Willemse</ns2:Name>
</ns2:ResultData>
</ns2:TestReply>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
这是我得到的响应(使用WCF测试客户端进行测试时):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<GetDataResponse xmlns="http://www.test.org/test/2007/00">
<TestReply xmlns:a="http://www.test2.org/test2/types" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Result>
<a:ActionSuccessful>true</a:ActionSuccessful>
</a:Result>
<a:ResultData>
<a:Name>Maikel Willemse</a:Name>
</a:ResultData>
</TestReply>
</GetDataResponse>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
我的服务界面如下所示:
[ServiceContract(Namespace = "http://www.test.org/test/2007/00")]
public interface IService1
{
[OperationContract]
[return: MessageParameter(Name = "TestReply")]
GetDataResponse GetData(string name);
}
Run Code Online (Sandbox Code Playgroud)
服务类:
public class Service1 : IService1
{
public GetDataResponse GetData(string name)
{
return new GetDataResponse
{
Result = new Result {ActionSuccessful …Run Code Online (Sandbox Code Playgroud)