带有Resp Api的无效请求 [英] Invalid request in Resp Api with Post

查看:58
本文介绍了带有Resp Api的无效请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        [OperationContract]
        [WebInvoke(Method = "POST",
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "/DemoInsert")]
        int DemoInsert(Demo demo);

//Implementation

 public int DemoInsert(Demo demo)
        {
            DriverDetails driver = new DriverDetails();
            return driver.DemoInsert(demo);
        }

[DataContract]
    public class Demo
    {
        [DataMember]
        public string name { get; set; }
        [DataMember]
        public DateTime dob { get; set; }
        [DataMember]
        public int cid { get; set; }
        [DataMember]
        public string address { get; set; }

    }

/* I am trying to consume the service in the console application and getting 405 error, when i am trying to access the service in the console.

The basic idea if this service works fine i need to consume this service in andriod studio to do an isert.*/

//Calling in the Console

 Demo d = new  Demo();
 d.address = "Address1";
 d.cid = 11;
 d.dob = DateTime.Today;
 d.name = "gopi";

WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
 MemoryStream stream1 = new MemoryStream();
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Demo));
            serializer.WriteObject(stream1, d);
            byte[] data = client.UploadData("http://172.16.8.99:35802/IRestService.svc/DemoInsert", "POST", stream1.ToArray());

            stream1 = new MemoryStream(data);
            serializer = new DataContractJsonSerializer(typeof(Demo));
            string result = (string)serializer.ReadObject(stream1);


推荐答案

我是Gopi,

Hi Its me Gopi,

谢谢您在这里发布.

根据您的问题与WCF更为相关,我将其移至 Windows Communication Foundation,序列化和网络论坛  论坛以获取适当的支持.

According to your question is more related to WCF, I will move it to  Windows Communication Foundation, Serialization, and Networking forum for suitable support.

Visual C#讨论并询问C#编程语言,IDE,库,示例和工具.

The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools.

如果您有一些语法或代码错误,请随时与我们联系.我们将尽力为您提供解决方案.

If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

感谢您的理解与合作.

Thanks for your understanding and cooperation. 

最好的问候,

温迪


这篇关于带有Resp Api的无效请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆