wcf rest:使用" BodyStyle = WebMessageBodyStyle.Wrapped",我无法在浏览器中看到对象参数

时间:2014-07-11 06:35:18

标签: wcf

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

[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

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

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

screen shot

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

2 个答案:

答案 0 :(得分:0)

在IIS上托管它而不是使用visual studio in-build服务器对我来说是个窍门。

答案 1 :(得分:0)

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

离。

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...
}