如何从 C# 网络服务生成 WSDL 文件 [英] How to generate a WSDL file from a C# webservice

查看:82
本文介绍了如何从 C# 网络服务生成 WSDL 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个这样的 WebService:

[WebService(Namespace = "http://ns")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]公共类 GroupManagerService : WebService{公共 GroupManagerService(){}[网络方法]public bool MyMethod(字符串登录名,字符串国家){//代码在这里...}}

是否可以在不连接到正在运行的服务的情况下为此代码生成 WSDL 文件?我搜索并找到了有关 SvcUtil.exe & 的信息.wsdl.exe,但这些仅在从正在运行的 WebService 中检索 WSDL 时有效.

(对于java,有一个名为java2wsdl的工具,是否有与c#等效的工具?)



:更新:
这个问题的上下文是我想将新的 CustomWebService 添加到 SharePoint,它应该使用 WSPBuilder 部署在 SharePoint 上的 _vti_bin 文件夹中.另请参阅我在 SharePoint.SE 上的帖子.

我想自动生成(使用 msbuild 命令)'MyServicewsdl.aspx' &'MyServicedisco.wsdl' 必须放在 _vti_bin 文件夹中.



也许我错过了一些东西?svcutil.exe 的输出是:

binDebug>SvcUtil.exe MyWebService.dllMicrosoft (R) 服务模型元数据工具[Microsoft (R) Windows (R) 通信基础,版本 3.0.4506.2152]版权所有 (c) 微软公司.版权所有.正在生成元数据文件...警告:未生成元数据文件.没有出口服务合同.要导出服务,请使用/serviceName 选项.要导出数据合同,请指定cify/dataContractOnly 选项.这有时会发生在某些安全上下文,例如当程序集通过 UNC 网络文件共享加载时.如果是这种情况,尝试将程序集复制到受信任的环境中并运行克它.

解决方案

我创建了一个工具,该工具可以从包含一个或多个 Web 服务的已编译 C# 程序集 (dll) 生成 WSDL 文件.通常,您需要一个托管 .asmx 的运行服务(IIS 或其他),以便您可以使用/MyWebService.asmx?wsdl

检索 WSDL

此工具使用反射生成一个 WSDL 文件,以从程序集 (dll) 中检索所有信息.

可以在 https://github.com/StefH/WSDLGenerator 找到下载>

I've created a WebService like this:

[WebService(Namespace = "http://ns")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GroupManagerService : WebService
{
    public GroupManagerService()
    {
    }

    [WebMethod]
    public bool MyMethod(string loginname, string country)
    {
        // code here...
    }
}

Is it possible to generate a WSDL file for this code without connecting to a running service? I searched and I found information about SvcUtil.exe & wsdl.exe, but these work only when retrieving the WSDL from a running WebService.

(For java, there is a tool called java2wsdl, is there a equivalent for c# ?)



:Update:
The context for this question is that I want to add new CustomWebService to SharePoint which should deployed using WSPBuilder in the _vti_bin folder on SharePoint. See also my post on SharePoint.SE.

And I want to automatically generate (using msbuild commands) the 'MyServicewsdl.aspx' & 'MyServicedisco.wsdl' which must be placed in the _vti_bin folder.



Maybe I'm missing some things? Output from svcutil.exe is:

binDebug>SvcUtil.exe MyWebService.dll
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation.  All rights reserved.

Generating metadata files...
Warning: No metadata files were generated. No service contracts were exported.
 To export a service, use the /serviceName option. To export data contracts, spe
cify the /dataContractOnly option. This can sometimes occur in certain security
contexts, such as when the assembly is loaded over a UNC network file share. If
this is the case, try copying the assembly into a trusted environment and runnin
g it.

解决方案

I've created a tool which can generate a WSDL file from a compiled c# assembly (dll) which contains one or more WebServices. Normally you require a running service (IIS or other) which hosts the .asmx so that you can retrieve the WSDL using /MyWebService.asmx?wsdl

This tool generate a WSDL file using reflection to retrieve all information from an assembly (dll).

Download can be found at https://github.com/StefH/WSDLGenerator

这篇关于如何从 C# 网络服务生成 WSDL 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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