Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF客户端发送原始格式_Wcf_Xamarin_Restsharp - Fatal编程技术网

WCF客户端发送原始格式

WCF客户端发送原始格式,wcf,xamarin,restsharp,Wcf,Xamarin,Restsharp,我正在尝试使用restsharp和xamarine将一些数据发送到wcf服务器并获取返回值。以下是服务器端的代码: public interface IRestService { [OperationContract(Name = "Login")] [WebInvoke(UriTemplate = "/Login/", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMe

我正在尝试使用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);
var client=new RestClient(“http://192.168.0.187:9226/RestService.svc");
AddDefaultHeader(“ContentType”、“application/json”);
var request=new RestRequest(String.Format(“/Login/”,“198440”);
request.Method=Method.POST;
AddParameter(“用户名”、“blabla”);
request.RequestFormat=DataFormat.Json;
IRestResponse response1=客户端。执行(请求);
当我跟踪我的wcf时,我不断得到“传入消息具有意外的消息格式‘Raw’。操作的预期消息格式为‘Xml’、‘Json’。”
有什么帮助吗?

您不应该使用AddParameter。这将为帖子创建一个表单编码的正文

相反:

request.RequestFormat = DataFormat.Json;
request.AddBody(new { "username" = "blabla"}));

不应使用AddParameter。这将为帖子创建一个表单编码的正文

相反:

request.RequestFormat = DataFormat.Json;
request.AddBody(new { "username" = "blabla"}));

不应使用AddParameter。这将为帖子创建一个表单编码的正文

相反:

request.RequestFormat = DataFormat.Json;
request.AddBody(new { "username" = "blabla"}));

不应使用AddParameter。这将为帖子创建一个表单编码的正文

相反:

request.RequestFormat = DataFormat.Json;
request.AddBody(new { "username" = "blabla"}));
将“BodyStyle=WebMessageBodyStyle.Wrapped”改为“BodyStyle=WebMessageBodyStyle.Bare”怎么样将“BodyStyle=WebMessageBodyStyle.Wrapped”改为“BodyStyle=WebMessageBodyStyle.Bare”怎么样“BodyStyle=WebMessageBodyStyle.Wrapped”到“BodyStyle=WebMessageBodyStyle.Bare”