我有一个如下的网络服务,
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json/{jsondata}")]
void JSONData(string jsondata);
}
public class RestServiceImpl : IRestServiceImpl
{
List<ClsTripAdvisorData> lst = new List<ClsTripAdvisorData>();
ClsTripAdvisorData _ClsTripAdvisorData = null;
#region IRestServiceImpl Members
public void JSONData(string jsondata)
{
string[] data = jsondata.Split('&');
}
}
它期待一个 JSON 输入。当我通过将 JSON 字符串作为查询字符串请求传递如下来使用海报测试此服务时,
http://localhost:1162/RestServiceImpl.svc/json/api_version=4 &hotels=[{"ta_id":97497,"partner_id":"229547","partner_url":"http://partner.com/deeplink/to/229547"},{"ta_id":97832,"partner_id":"id34234","partner_url":"http://partner.com/deeplink/to/id34234"}] &start_date=2013-07-01 &end_date=2013-07-03 &num_adults=2 &num_rooms=1 &lang=en_US ¤cy=USD &user_country=US &device_type=d &query_key=6167a22d1f87d2028bf60a8e5e27afa7_191_1360299600000_2_2
这里我的字符串参数是api_version=4 &hotels=[{"ta_id":97497,"partner_id":"229547","partner_url":"http://partner.com/deeplink/to/229547"},{"ta_id":97832,"partner_id":"id34234","partner_url":"http://partner.com/deeplink/to/id34234"}] &start_date=2013-07-01 &end_date=2013-07-03 &num_adults=2 &num_rooms=1 &lang=en_US ¤cy=USD &user_country=US &device_type=d &query_key=6167a22d1f87d2028bf60a8e5e27afa7_191_1360299600000_2_2
它在调试时没有达到服务方法断点。
同时它适用于以下 JSON,
http://localhost:1162/RestServiceImpl.svc/json/asd
不接受 JSON 字符串输入的服务方法,
我只想将此字符串作为我的 Web 服务的正文部分发送。但我不知道如何使用 wcf 休息服务发送和接收此 json 字符串