我需要我的wcf服务将以下列格式回复消息。
<Date>
1;test;306;values;1,2;product
</Date>
我如何创建我的WCF服务。
提供一些示例代码。
答案 0 :(得分:0)
通过这种设置,您可以非常接近(并且可能尽可能接近):
服务合同:
[ServiceContract(Namespace="")]
public interface IService1
{
[OperationContract]
Response GetData(Request input);
}
请求和响应的消息合同
[MessageContract(IsWrapped = false)]
public class Request
{
[MessageBodyMember(Name = "DateRequest")]
public string Input { get; set; }
}
[MessageContract(IsWrapped = false)]
public class Response
{
[MessageBodyMember(Name = "Date")]
public string ReturnString { get; set; }
}
当您基于此实现服务,并使用正确的值调用它时,您应该得到这样的XML响应:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<Date>1;test;306;values;1,2;product</Date>
</s:Body>
</s:Envelope>