代码之家  ›  专栏  ›  技术社区  ›  Stef Heyenrath Dariusz Woźniak

如何从C WebService生成WSDL文件

  •  17
  • Stef Heyenrath Dariusz Woźniak  · 技术社区  · 14 年前

    我创建了这样一个Web服务:

    [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时,这些方法才有效。

    (用于 爪哇 ,有一个工具名为 Java2WSDL ,是否有等效的 C.* ?)



    :更新:
    此问题的上下文是,我要将新的CustomWebService添加到SharePoint,该服务应使用wspbuilder部署在SharePoint的“vti”bin文件夹中。 另请参见 my post 在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.
    
    3 回复  |  直到 6 年前
        1
  •  15
  •   Stef Heyenrath Dariusz Woźniak    6 年前

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

    此工具使用反射从程序集(dll)中检索所有信息来生成WSDL文件。

    下载可在 https://github.com/StefH/WSDLGenerator

        2
  •  6
  •   John Saunders    14 年前

    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
  •  2
  •   jpsstavares    14 年前

    svcutil.exe肯定会在服务关闭时生成WSDL。正确用法是svcutil your.executable.dll(exe)。 我经常使用它,所以我确信它会生成WSDL。