wcf rest :通过使用“BodyStyle = WebMessageBodyStyle.Wrapped",我无法在浏览器中看到对象参数 [英] wcf rest : by using "BodyStyle = WebMessageBodyStyle.Wrapped", I am not able to see object parameters in browser

查看:31
本文介绍了wcf rest :通过使用“BodyStyle = WebMessageBodyStyle.Wrapped",我无法在浏览器中看到对象参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种方法CreateAccount",如下所述

I have one method "CreateAccount" as mentioned below

[OperationContract]
[WebInvoke(UriTemplate = "CreateAccount", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public CreateAccountServiceResponse CreateAccount(AuthenticateApplication Application, ApplicationCustomer Customer, CustomerService Service, Option Options)
{
    // Some Implementation
}

如果我正在使用

BodyStyle = WebMessageBodyStyle.Wrapped

然后我无法在浏览器中找到请求/响应参数.相反,它显示为

then I am not able to find Request/Response parameters in browser. Instead it is showing like

Message    direction    Format  Body
Request     Unknown     Cannot infer schema. The Request body is wrapped.
Response    Unknown     Cannot infer schema. The Response body is wrapped

有人可以为此提供解决方案,以便我能够找到请求/响应格式.

Can someone provide solution to this so that I can able to find request/response format.

推荐答案

如果您可以将所有输入包装到传输类中,那么您可以删除 BodyStyle 属性,一切都会显示出来很好.

If you can wrap all of your inputs into a transport class, then you can remove the BodyStyle attribute, and everything will show up nicely.

例如

public class CreateAccountServiceRequest {
    public AuthenticateApplication Application { get; set; }
    public ApplicationCustomer Customer { get; set; }
    public CustomerService Service { get; set; }
    public Option Options { get; set; }
}

[OperationContract]
[WebInvoke(UriTemplate = "CreateAccount", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public CreateAccountServiceResponse CreateAccount(CreateAccountServiceRequest request)
{
    // you can even reuse the existing method, as long as you don't expose it or change the UriTemplate so there's no conflict
    return CreateAccount(request.Application, request.Customer, request...
}

这篇关于wcf rest :通过使用“BodyStyle = WebMessageBodyStyle.Wrapped",我无法在浏览器中看到对象参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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