我已经在C#中创建了一个IIS服务,并将其部署到RESTful。当我访问服务HeadOffice.svc时,我可以选择查看WSDL (HeadOffice.svc?wsdl)。我想要做的是可以选择查看WADL (例如HeadOffice.svc?wadl)。这个是可能的吗?
我在各处都读到过,普遍的观点是这不是最佳实践。然而,我需要WADL来完成一项学校作业,因此任何帮助都将不胜感激。
发布于 2012-10-19 15:05:25
假设您已经知道WADL不是标准的,也不是广泛支持的。当有人需要WADL时,最好使用WS*/SOAP服务+ WSDL。所以你的任务看起来很奇怪。
无论如何,微软的任何REST实现、WCF3.5REST入门工具包、WCF4REST和ASP.NET WebAPI都不支持WADL。
目前还没有可靠的工具用于.NET的WADL。
当您的目标是使用WADL生成C#客户端代码时,请相信我,您将花费更多的时间来自己编写客户端代码。对此有更好的解决方案。
您可以使用新的类,如HttpClient类或RestSharp或类似的库,轻松地手动编写您的客户端,这将比谷歌搜索可靠的.NET解决方案更快
关于堆栈溢出的类似问题:Restful service in .NET with WADL instead of WSDL
UPDATE -Swagger:多年来,swagger已经确立了自己的这种格式。您可以在Swagger editor中使用swagger的YAML开始编写服务定义,或者让现有服务使用Swashbuckle库为.NET生成swagger。第二个是WSDL,swagger编辑器可以让您生成客户端和服务器样板。无论你是在生成你的服务器或客户端,还是不喜欢它,swagger实际上是一个非常好的REST服务合同交换格式,虽然不是很理想,但却是个不错的选择。
发布于 2018-07-26 20:43:04
为什么选择Swagger4Wcf
·手动为swagger编写yaml描述并维护它,尤其是WCF服务很无聊。
·有一个名为Swagger4WCF的nuget包,它会自动为每个匹配WCF (ServiceContract/OperationContract/WebGet/WebInvoke)使用的属性的接口生成swagger2.0的yaml。
2. Swagger在后台的工作方式
Swagger4WCF使用NuPack构建后模式在构建时触发。
https://www.codeproject.com/Tips/1190360/How-to-setup-a-managed-postbuild-without-scripting
在应用程序中实现Swagger的步骤:
WCF
我们必须在Global.asax内部的Application_Start方法中添加路由
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("v1/rest", new WebServiceHostFactory(), typeof(BookStore)));
RouteTable.Routes.Add(new ServiceRoute("api-docs", new WebServiceHostFactory(), typeof(SwaggerWcfEndpoint)));
}注意:编辑Web.config并在system.serviceModel块中添加以下内容(如果它还不存在
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>响应自动类型(可选)
我们必须将以下内容添加到Web.config中。这将允许WCF服务根据Content-Type标头接受请求并发送回复。
<behavior name="webHttpBehavior">
<webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>[SwaggerWcfPath("Get book", "Retrieve a book from the store using its id")] [WebGet(UriTemplate = "/books/{id}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] [OperationContract] Book ReadBook(string id);
·将SwaggerWcf和AspNetCompatibilityRequirements属性添加到提供服务基本路径的类中。
·对于每个方法,添加SwaggerWcfTag以对该方法进行分类,并为来自服务的每个可能的响应添加theSwaggerWcfResponse。
[SwaggerWcfTag("Books")]
[SwaggerWcfResponse(HttpStatusCode.OK, "Book found, value in the response body")]
[SwaggerWcfResponse(HttpStatusCode.NoContent, "No books", true)]
public Book[] ReadBooks()
{
}[DataContract] [Description("Book with title, first publish date, author and language")] [SwaggerWcfDefinition(ExternalDocsUrl = "http://en.wikipedia.org/wiki/Book", ExternalDocsDescription = "Description of a book")]
公共类书籍{ DataMember公共字符串Id { get;set;} DataMember公共字符串标题{ get;set;} DataMember public int FirstPublished { get;set;} DataMember公共作者{ get;set;} DataMember公共语言语言{ get;set;} }
参考资料:- https://github.com/abelsilva/swaggerwcf
这就是wcf for Swagger的实现。如果您遇到任何问题,请随时联系。
谢谢你,阿比
https://stackoverflow.com/questions/12968007
复制相似问题