Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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
C# 无法从xamarin的PCL中的wcf服务获取响应正文_C#_Android_Json_Wcf_Xamarin - Fatal编程技术网

C# 无法从xamarin的PCL中的wcf服务获取响应正文

C# 无法从xamarin的PCL中的wcf服务获取响应正文,c#,android,json,wcf,xamarin,C#,Android,Json,Wcf,Xamarin,我试图在visual studio中使用xamarin android的PCL中的wcf服务,在调用该服务时,我希望获得json响应正文。但在这里,除了200状态之外,我不会获得任何响应正文。请任何人帮助我。任何建议和帮助都非常感谢。下面是使用的代码 类别1.cs namespace XamarinServiceCall { public sealed class Class1 : IRestService { public async Task<str

我试图在visual studio中使用xamarin android的PCL中的wcf服务,在调用该服务时,我希望获得json响应正文。但在这里,除了200状态之外,我不会获得任何响应正文。请任何人帮助我。任何建议和帮助都非常感谢。下面是使用的代码

类别1.cs

 namespace XamarinServiceCall
{
    public sealed class Class1 : IRestService
    {

        public async Task<string> GetData(UserModel model)
        {
            using (var client = new HttpClient())
            {
                var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string,string>("domainName",model.domainName ),
            new KeyValuePair<string, string>("userName", model.userName),
            new KeyValuePair<string, string>("password", model.password),
            new KeyValuePair<string, string>("loginFrom", model.loginFrom),
        });
var result = await client.PostAsync("http://xamarin-rest-service/LoginService/ValidateLogin", content);

            return await result.Content.ReadAsStringAsync();


            }
        }
    }
} 
命名空间服务调用
{
公共密封类别1:IRestService
{
公共异步任务GetData(用户模型)
{
使用(var client=new HttpClient())
{
var content=newformurlencodedcontent(new[]
{
新的KeyValuePair(“域名”,model.domainName),
新的KeyValuePair(“用户名”,model.userName),
新的KeyValuePair(“密码”,型号密码),
新的KeyValuePair(“loginFrom”,model.loginFrom),
});
var result=wait client.PostAsync(“http://xamarin-rest-service/LoginService/ValidateLogin“,内容);
返回wait result.Content.ReadAsStringAsync();
}
}
}
} 
MAinActivity.cs

namespace ServiceSample
{
    [Activity(Label = "LayoutSample", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
            protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            XamarinServiceCall.Class1 serviceClass = new XamarinServiceCall.Class1();
           var model = new XamarinServiceCall.UserModel { domainName = "domainname" ,userName = "username" , password = "password" ,loginFrom = "App" };

            var result = await serviceClass.GetData(model);
            button.Text = "get call says: " + result;

        }
    }
}
名称空间服务示例
{
[活动(Label=“LayoutSample”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共课活动:活动
{
受保护的异步重写void OnCreate(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
//从布局资源中获取我们的按钮,
//并在其上附加一个事件
Button Button=FindViewById(Resource.Id.MyButton);
XamarinServiceCall.Class1 serviceClass=新的XamarinServiceCall.Class1();
var model=new XamarinServiceCall.UserModel{domainName=“domainName”,userName=“userName”,password=“password”,loginFrom=“App”};
var结果=等待serviceClass.GetData(模型);
button.Text=“get call说:”+结果;
}
}
}
下图显示了我在调试结果变量时获得的数据

下面是我需要发送(URL)并获得json正文响应的内容

=domainname&userName=userName&password=password&loginFrom=App

回应邮递员:

“域名类型”:2,“名字”:dallia,“状态”:2,“用户ID”:3


非常感谢任何帮助或建议。请帮助我我对c#和xamarin非常陌生。

我使用示例中的参数值创建了一个邮递员请求,API调用不会返回您显示为邮递员响应的内容。返回200,正文为空(内容长度=0)。似乎是参数值导致了这种行为。@Mark Larter请参考此链接我发布了相同的问题,我用更多图像对其进行了编辑以提高清晰度我使用示例中的参数值创建了一个邮递员请求,API调用不会返回您显示为邮递员响应的内容。返回200,正文为空(内容长度=0)。似乎是参数值导致了这种行为。@Mark Larter请参考此链接,我发布了相同的问题,为了更清晰,我使用了更多图像对其进行了编辑