【问题标题】:wcf rest : by using "BodyStyle = WebMessageBodyStyle.Wrapped", I am not able to see object parameters in browserwcf rest:通过使用“BodyStyle = WebMessageBodyStyle.Wrapped”,我无法在浏览器中看到对象参数
【发布时间】:2015-07-25 00:16:49
【问题描述】:

我有一种方法“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

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

【问题讨论】:

标签: wcf


【解决方案1】:

将它托管在 IIS 上而不是使用 Visual Studio 内置服务器对我来说是诀窍。

【讨论】:

    【解决方案2】:

    如果您可以将所有输入包装到一个传输类中,那么您可以删除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...
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-04
      • 2015-10-24
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多