如何使用 POSTMAN 或任何客户端工具应用程序使用自定义对象调用 RestFul WCF POST 服务? [英] How to call RestFul WCF POST service With Custom Object using POSTMAN or any client tool application?

查看:40
本文介绍了如何使用 POSTMAN 或任何客户端工具应用程序使用自定义对象调用 RestFul WCF POST 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,假设我想使用 POSTMAN 或任何其他 Rest 服务客户端工具来调用我的代码,我该怎么做?我的参数之一是 SwitchStatus(这是我自己定义的某个对象)

okay lets say I want to use POSTMAN or any other Rest service client tool to call my code, how should can I do it? one of my parameters is SwitchStatus (it's some object i defined myself)

当使用 POSTMAN 调用此服务时,我是否应该在请求正文中包含一些内容?如果是这样,格式是什么?任何帮助将不胜感激

When calling this service with POSTMAN, should I include something within the body of the request? If so, what will be the format? any help would be appreciated it

谢谢

        [WebInvoke(UriTemplate = "/SwitchStatus", Method = "POST")]
        [OperationContract]
        [Description("Request to update switch status, true for close the switch")]
        void UpdateSwitchStatus(SwitchStatus data);

我希望我的服务器收到来自 POSTMAN 的请求.

I will expect my server to receive the request from POSTMAN.

推荐答案

Buddy,你说得对,我们应该考虑是否包含参数名称.实际上是由 Bodystyle 属性决定的.

Buddy, You are right, we should consider whether including the name of the parameter. Actually it is determined by the Bodystyle property.

[OperationContract]
        [WebInvoke(RequestFormat =WebMessageFormat.Json,ResponseFormat =WebMessageFormat.Json,BodyStyle =WebMessageBodyStyle.Bare)]
        CompositeType GetDataUsingDataContract(CompositeType composite);

    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
}

根据上面的 BodyStyle 属性,请求正文是,

Depending on the above BodyStyle property, the request body is,

{"StringValue":"Hello","BoolValue":true}  


请参考我之前的回复.里面有细致的描述.
使用JSON获取对象为空WCF 服务
如果有什么我可以帮忙的,请随时告诉我.


Please refer to my previous reply. There is a meticulous description in it.
Get the object is null using JSON in WCF Service
Feel free to let me know if there is anything I can help with.

这篇关于如何使用 POSTMAN 或任何客户端工具应用程序使用自定义对象调用 RestFul WCF POST 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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