如何从 C# Web 服务生成 WSDL 文件
我创建了一个像这样的 WebService:
[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 generated a WSDL file for this code withoutconnecting to a running service? 我搜索并找到了有关 SvcUtil.exe & 的信息。 wsdl.exe,但这些仅在从正在运行的 WebService 检索 WSDL 时起作用。
(对于java,有一个名为java2wsdl的工具,c#有等效的工具吗?)
:更新:
此问题的上下文是我想向 SharePoint 添加新的 CustomWebService,该服务应使用 SharePoint 上的 _vti_bin 文件夹中的 WSPBuilder 进行部署。 另请参阅我在 SharePoint.SE 上的帖子。
我想自动生成(使用 msbuild 命令)'MyServicewsdl.aspx' & 'MyServicedisco.wsdl' 必须放置在 _vti_bin 文件夹中。
也许我错过了一些东西? svcutil.exe 的输出是:
bin\Debug>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 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:
bin\Debug>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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我创建了一个工具,可以从包含一个或多个 Web 服务的已编译 C# 程序集 (dll) 生成 WSDL 文件。
通常,您需要托管 .asmx 的正在运行的服务(IIS 或其他),以便您可以使用 /MyWebService.asmx?wsdl 检索 WSDL。
此工具使用反射生成 WSDL 文件,以从程序集 (dll) 检索所有信息。
下载地址:https://github.com/StefH/WSDLGenerator
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
请参阅 svcutil /?
See
svcutil /?
Svcutil.exe 肯定会在服务关闭时生成 WSDL。正确的用法是 svcutil your.executable.dll(exe)。
我经常使用它,所以我确信它会生成 WSDL。
Svcutil.exe will definitely generate the WSDL with the service down. The correct usage is svcutil your.executable.dll(exe).
I'm using this a lot so I'm sure it will generate the WSDL.