Как сгенерировать 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...
    }
}

Возможно ли создать файл WSDL для этого кода без подключения к работающей службе? Я искал и нашел информацию о SvcUtil.exe и wsdl.exe, но они работают только при извлечении WSDL из работающего WebService.

(Для java существует инструмент с именем java2wsdl, есть ли эквивалент для С#?)



: Обновление:
Контекст для этого вопроса заключается в том, что я хочу добавить новый CustomWebService в SharePoint, который должен быть развернут с использованием WSPBuilder в папке _vti_bin в SharePoint. См. Также мой пост в 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.

Ответы

Ответ 1

Я создал инструмент, который может сгенерировать WSDL файл из скомпилированной сборки С# (dll), которая содержит один или несколько WebServices. Обычно вам требуется работающий сервис (IIS или другой), который размещает .asmx, чтобы вы могли получить WSDL с помощью /MyWebService.asmx?wsdl

Этот инструмент генерирует WSDL файл с использованием отражения для извлечения всей информации из сборки (dll).

Загрузка можно найти на https://github.com/StefH/WSDLGenerator

Ответ 2

См. svcutil /?

                          -= METADATA EXPORT =-

Description: svcutil.exe can export metadata for services, contracts and data types in compiled assemblies. To
    export metadata for a service, you must use the /serviceName option to indicate the service you would like
    to export. To export all Data Contract types within an assembly use the /dataContractOnly option. By
    default metadata is exported for all Service Contracts in the input assemblies.

Syntax: svcutil.exe [/t:metadata] [/serviceName:<serviceConfigName>] [/dataContractOnly] <assemblyPath>*

 <assemblyPath> - The path to an assembly that contains services, contracts or Data Contract types to be
                  exported. Standard command-line wildcards can be used to provide multiple files as input.

Options:

 /serviceName:<serviceConfigName> - The config name of a service to export. If this option is used, an
                                    executable assembly with an associated config file must be passed as
                                    input. Svcutil will search through all associated config files for the
                                    service configuration. If the config files contain any extension types,
                                    the assemblies containing these types must either be in the GAC or
                                    explicitly provided using the /r option.
 /reference:<file path>           - Add the specified assembly to the set of assemblies used for resolving
                                    type references. If you are exporting or validating a service that uses
                                    3rd-party extensions (Behaviors, Bindings and BindingElements) registered
                                    in config use this option to locate extension assemblies that are not in
                                    the GAC.  (Short Form: /r)
 /dataContractOnly                - Operate on Data Contract types only. Service Contracts will not be
                                    processed. (Short Form: /dconly)
 /excludeType:<type>              - The fully-qualified or assembly-qualified name of a type to exclude from
                                    export. This option can be used when exporting metadata for a service or a
                                    set of service contracts to exclude types from being exported. This option
                                    cannot be used with the /dconly option. (Short Form: /et)

Ответ 3

Svcutil.exe определенно сгенерирует WSDL с отключенной службой. Правильное использование - svcutil your.executable.dll(exe). Я использую это много, поэтому я уверен, что он будет генерировать WSDL.