【问题标题】:Issue with Swagger Wcf Generated Example CodeSwagger Wcf 生成的示例代码的问题
【发布时间】:2017-05-10 16:14:59
【问题描述】:

我正在尝试使用https://github.com/abelsilva/swaggerwcf

但是在我们的 WCF 方法中使用它时遇到问题

一个例子是这样的:

public ETemplate GetETemplate(int eTemplateId)

我们通过 webHttpBinding 暴露了 svc,并在行为中设置了 enableWebScript

当我们通常使用 REST 从 jQuery 访问它时,我们会在 Post 中使用它

{"eTemplateId": "26000"}

但是从 SwaggerWcf 生成的示例数据中,我们得到的只是一个像这样在 POST 中传递的整数

26000

下面是我如何在接口上装饰方法,我认为这是正确的,因为 WebMessageBodyStyle 正确设置为 Wrapped 而不是 Bare。

我错过了一些简单的东西吗?

   [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST",
            RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]

【问题讨论】:

    标签: c# rest wcf swagger swagger-wcf


    【解决方案1】:

    您能否提供有关您的问题的更多信息。 似乎有些不对劲。我认为请求格式不会在招摇实施中产生错误。 尝试下载项目招摇。 https://github.com/superstator/Swaggeratr 这是 SwaggerWCF 的初始版本,是 SwaggerWCF 中的分支转换。您会发现它们是初始集成的一些有用示例。一般不会有太大变化。

    在 Swaggerator 中,您会找到类似这样的 post 方法定义。

    [Tag("InternalUse")]
            [OperationSummary("Does stuff.")]
            [OperationNotes("I mean, it does some really interesting stuff. Stuff like you wouldn't believe.")]
            [ResponseCode(400, "Four hundred error")]
            [ResponseCode(200, "OK")]
            [ResponseCode(205, "Some error")]
            [ResponseCode(404, "Not found")]
            [ResponseCode(401, "Something weird happened")]
            [ResponseCode(301, "Three O one Something weird happened")]
            [OperationContract]
            [WebInvoke(UriTemplate = "/data", Method = "POST", RequestFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Bare)]
            CompositeType GetDataUsingDataContract(CompositeType composite);
    

    尝试检查该示例实现,并请发布有关您遇到的问题的更多详细信息。否则,提供更多帮助会很复杂。

    我只是创建了一个分叉。因为,我在部署中发现了一些问题。 https://github.com/gabrielacosta/swaggerwcf 如果你下载那个分支。该代码正在运行,也许它可以提供更好的视角。

    【讨论】:

      猜你喜欢
      • 2017-10-08
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 2020-02-10
      相关资源
      最近更新 更多