Mic*_*han 5 .net xml wcf json web-services
我有一个返回XML响应的现有Web服务,我想添加一些返回JSON的新方法.我是否必须创建一个以JSON格式返回的单独Web服务,还是可以混合使用?
如果我使用ResponseFormat = WebMessageFormat.JSON我需要使用[DataContractFormat]注释服务,但我似乎没有那个和xml类型响应格式所需的[XmlSerializerFormat].
我不明白为什么这是不可能的。您可以使用 [ServiceContract] 属性(而不是 DataContractFormat)来注释服务。它应该看起来像
[ServiceContract]
public interface IDoStuff
{
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "DoStuff",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
TestObj DoWork(TestInputObj Inp);
}
Run Code Online (Sandbox Code Playgroud)
要使其成为 xml,只需更改响应格式即可。当您执行 post 命令时,您将获得 json,具有 xml 格式的单独方法将为您提供 xml。
| 归档时间: |
|
| 查看次数: |
3744 次 |
| 最近记录: |