我创建了这样的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...
}
}
是否可以在不连接到正在运行的服务的情况下为该代码生成WSDL文件?
我进行了搜索,发现了有关 SvcUtil.exe 和 wsdl.exe 的信息,但这些信息仅在从运行中的WebService检索WSDL时有效。
(对于 java ,有一个名为 java2wsdl 的工具,是否有等效于 C#的工具?)
:更新:
此问题的上下文是我要向SharePoint添加新的CustomWebService,应使用WSPBuilder在SharePoint的_vti_bin文件夹中进行部署。
另请参阅SharePoint.SE上的my post。
我想自动生成(使用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.
最佳答案
我创建了一个工具,该工具可以从包含一个或多个WebServices的已编译C#程序集(dll)生成WSDL文件。
通常,您需要承载.asmx的运行服务(IIS或其他),以便可以使用/MyWebService.asmx?wsdl检索WSDL。
该工具使用反射生成WSDL文件,以从程序集(dll)检索所有信息。
可以在https://github.com/StefH/WSDLGenerator找到下载
关于c# - 如何从C#Web服务生成WSDL文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2340797/