【发布时间】:2014-05-13 13:58:51
【问题描述】:
我正在尝试使用 restsharp 和 xamarine 向 wcf 服务器发送一些数据并获取返回值。这是服务器端的代码:
public interface IRestService
{
[OperationContract(Name = "Login")]
[WebInvoke(UriTemplate = "/Login/", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json,RequestFormat = WebMessageFormat.Json)]
Boolean Login(String username);
及登录的实现:
Boolean IRestService.Login(string username)
{
if (string.IsNullOrEmpty(username))
return false;
else
return true;
}
这是我尝试在客户端建立连接的方式:
var client = new RestClient("http://192.168.0.187:9226/RestService.svc");
client.AddDefaultHeader("ContentType", "application/json");
var request = new RestRequest(String.Format("/Login/", "198440"));
request.Method = Method.POST;
request.AddParameter("username", "blabla");
request.RequestFormat = DataFormat.Json;
IRestResponse response1 = client.Execute<Boolean>(request);
当我跟踪我的 wcf 时,我不断收到“传入的消息具有意外的消息格式 'Raw'。操作的预期消息格式是 'Xml'、'Json'。” 有什么帮助吗?
【问题讨论】:
-
如何将“BodyStyle = WebMessageBodyStyle.Wrapped”改为“BodyStyle = webMessageBodyStyle.Bare”