当我调用方法XMLData
时,WebMessageFormat.Xml
我得到如下响应:
当我调用方法XMLData
时,WebMessageFormat.Json
我得到如下响应:
WCF 代码:
namespace RestService
{
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
string XMLData(string id);
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
string JSONData();
}
public class RestServiceImpl : IRestServiceImpl
{
#region IRestServiceImpl Members
public string XMLData(string id)
{
return "You requested product " + id;
}
public string JSONData()
{
return "You requested product ";
}
#endregion
}
}
配置文件:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="None" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<services>
<service name="RestService.RestServiceImpl">
<endpoint name="jsonEP"
address=""
binding="webHttpBinding"
behaviorConfiguration="json"
contract="RestService.IRestServiceImpl"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="json">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我的代码有什么问题?