2010-02-26 52 views
15

He creado un servicio web como esta:cómo generar un archivo WSDL de un servicio web C#

[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... 
    } 
} 

¿Es posible generar un archivo WSDL para este código sin necesidad de conectarse a un servicio en ejecución? He buscado y he encontrado información sobre SvcUtil.exe & wsdl.exe, pero estos funcionan solo cuando se recupera el WSDL de un WebService en ejecución.

(Para java, hay una herramienta llamada Java2WSDL, ¿existe un equivalente para C#?)



: Actualización:
El contexto de esta pregunta es que quiero agregar un nuevo CustomWebService a SharePoint que debería implementarse usando WSPBuilder en la carpeta _vti_bin en SharePoint. Ver también my post en SharePoint.SE.

y quiero generar automáticamente (utilizando comandos msbuild) la 'MyServicewsdl.aspx' & 'MyServicedisco.wsdl' que debe ser colocado en la carpeta _vti_bin.



Tal vez me falta algunas cosas? salida de svcutil.exe es:

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

¿Le pegan utilizando .NET 2.0? ¿Por qué estás creando nuevos servicios web ASMX? –

+0

Ver el texto de la pregunta actualizada ... –

+0

Debe usar la URL de la página de inicio del servicio ASMX, no la DLL del ensamblado, para obtener el archivo proxy. – vapcguy

Respuesta

15

He creado una herramienta que puede generar un archivo WSDL a partir de un ensamblado C# compilado (dll) que contiene uno o más WebServices. Normalmente se requieren de un servicio en ejecución (IIS u otro) que alberga el asmx para que pueda recuperar el WSDL utilizando /MyWebService.asmx?wsdl

Esta herramienta genera un archivo WSDL utilizando la reflexión para recuperar toda la información de un ensamblaje (dll).

descarga se puede encontrar en https://github.com/StefH/WSDLGenerator

+1

¿WSDLGenerator también funciona con WCF? Estoy buscando una solución para [esta pregunta] (http://stackoverflow.com/questions/11099335/bind-a-custom-wsdl-to-an-existing-wcf-service). –

5

Ver 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) 
2

Svcutil.exe definitivamente generar el WSDL con el servicio de abajo. El uso correcto es svcutil your.executable.dll (exe). Estoy usando esto mucho, así que estoy seguro de que generará el WSDL.

+0

svcutil.exe muestra el error "Advertencia: No se generaron archivos de metadatos" –

Cuestiones relacionadas