FileDocCategorySizeDatePackage
WsdlToDotnet.javaAPI DocApache Ant 1.7017330Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional.dotnet

WsdlToDotnet

public class WsdlToDotnet extends org.apache.tools.ant.Task
Converts a WSDL file or URL resource into a .NET language. Why add a wrapper to the MS WSDL tool? So that you can verify that your web services, be they written with Axis or anyone else's SOAP toolkit, work with .NET clients. This task is dependency aware when using a file as a source and destination; so if you <get> the file (with usetimestamp="true") then you only rebuild stuff when the WSDL file is changed. Of course, if the server generates a new timestamp every time you ask for the WSDL, this is not enough...use the <filesmatch> <condition> to to byte for byte comparison against a cached WSDL file then make the target conditional on that test failing. See "Creating an XML Web Service Proxy", "wsdl.exe" docs in the framework SDK documentation
version
0.5
ant.task
category="dotnet"
since
Ant 1.5

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
used for timestamp checking
private File
destFile
name of output file (required)
private String
language
language; defaults to C#
private boolean
server
flag set to true to generate server side skeleton
private String
namespace
namespace
private boolean
failOnError
flag to control action on execution trouble
protected String
extraOptions
any extra command options?
private String
protocol
protocol string. Exact value set depends on SOAP stack version.
private boolean
ideErrors
should errors come in an IDE format. This is WSE only.
private Vector
schemas
filesets of file to compile
private Schema
wsdl
our WSDL file.
private Compiler
compiler
compiler
public static final String
ERROR_DEST_FILE_IS_DIR
error message: dest file is a directory
public static final String
ERROR_NO_DEST_FILE
error message: no dest file
Constructors Summary
Methods Summary
public voidaddSchema(org.apache.tools.ant.taskdefs.optional.dotnet.WsdlToDotnet$Schema source)
add a new source schema to the compilation

since
Ant 1.7
param
source a nested schema element.

        schemas.add(source);
    
public voidexecute()
do the work by building the command line and then calling it

throws
BuildException if validation or execution failed

        log("This task is deprecated and will be removed in a future version\n"
            + "of Ant.  It is now part of the .NET Antlib:\n"
            + "http://ant.apache.org/antlibs/dotnet/index.html",
            Project.MSG_WARN);

        if (compiler == null) {
            compiler = Compiler.createDefaultCompiler();
        }
        validate();
        NetCommand command = new NetCommand(this,
                "WSDL",
                compiler.getCommand());
        command.setFailOnError(failOnError);
        //fill in args
        compiler.applyExtraArgs(command);
        command.addArgument("/nologo");
        command.addArgument("/out:" + destFile);
        command.addArgument("/language:", language);
        if (server) {
            command.addArgument("/server");
        }
        command.addArgument("/namespace:", namespace);
        if (protocol != null) {
            command.addArgument("/protocol:" + protocol);
        }
        if (ideErrors) {
            command.addArgument("/parsableErrors");
        }
        command.addArgument(extraOptions);

        //set source and rebuild options
        boolean rebuild = true;
        long destLastModified = -1;

        //rebuild unless the dest file is newer than the source file
        if (destFile.exists()) {
            destLastModified = destFile.lastModified();
            rebuild = isRebuildNeeded(wsdl, destLastModified);
        }
        String path;
        //mark for a rebuild if the dest file is newer
        path = wsdl.evaluate();
        if (!compiler.supportsAbsoluteFiles() && wsdl.getFile() != null) {
            // Mono 1.0's wsdl doesn't deal with absolute paths
            File f = wsdl.getFile();
            command.setDirectory(f.getParentFile());
            path = f.getName();
        }
        command.addArgument(path);
        //add in any extra files.
        //this is an error in mono, but we do not warn on it as they may fix that outside
        //the ant build cycle.
        Iterator it = schemas.iterator();
        while (it.hasNext()) {
            Schema schema = (Schema) it.next();
            //mark for a rebuild if we are newer
            rebuild |= isRebuildNeeded(schema, destLastModified);
            command.addArgument(schema.evaluate());
        }
        //conditionally compile
        if (rebuild) {
            command.runCommand();
        }
    
private booleanisRebuildNeeded(org.apache.tools.ant.taskdefs.optional.dotnet.WsdlToDotnet$Schema schema, long destLastModified)
checks for a schema being out of data

param
schema url/file
param
destLastModified timestamp, -1 for no dest
return
true if a rebuild is needed.

        if (destLastModified == -1) {
            return true;
        }
        return !FILE_UTILS.isUpToDate(schema.getTimestamp(), destLastModified);
    
public voidsetCompiler(org.apache.tools.ant.taskdefs.optional.dotnet.WsdlToDotnet$Compiler compiler)
identify the compiler

since
Ant 1.7
param
compiler the enumerated value.

        this.compiler = compiler;
    
public voidsetDestFile(java.io.File destFile)
Name of the file to generate. Required

param
destFile filename


                   
        
        this.destFile = destFile;
    
public voidsetExtraOptions(java.lang.String extraOptions)
Any extra WSDL.EXE options which aren't explicitly supported by the ant wrapper task; optional

param
extraOptions The new ExtraOptions value

        this.extraOptions = extraOptions;
    
public voidsetFailOnError(boolean failOnError)
Whether or not a failure should halt the build. Optional - default is true.

param
failOnError new failure option

        this.failOnError = failOnError;
    
public voidsetIdeErrors(boolean ideErrors)
Defines wether errors are machine parseable. Optional, default=true

since
Ant 1.7
param
ideErrors a boolean value.

        this.ideErrors = ideErrors;
    
public voidsetLanguage(java.lang.String language)
set the language; one of "CS", "JS", or "VB" optional, default is CS for C# source

param
language language to generate

        this.language = language;
    
public voidsetMakeURL(boolean b)
flag to trigger turning a filename into a file:url ignored for the mono compiler.

param
b a boolean value.

        wsdl.setMakeURL(b);
    
public voidsetNamespace(java.lang.String namespace)
namespace to place the source in. optional; default ""

param
namespace new namespace

        this.namespace = namespace;
    
public voidsetProtocol(java.lang.String protocol)
what protocol to use. SOAP, SOAP1.2, HttpPost and HttpGet are the base options. Different version and implementations may. offer different options.

since
Ant 1.7
param
protocol the protocol to use.

        this.protocol = protocol;
    
public voidsetServer(boolean server)
flag to enable server side code generation; optional, default=false

param
server server-side flag

        this.server = server;
    
public voidsetSrcFile(java.io.File srcFile)
The local WSDL file to parse; either url or srcFile is required.

param
srcFile WSDL file

        wsdl.setFile(srcFile);
    
public voidsetUrl(java.lang.String url)
Sets the URL to fetch. Fetching is by wsdl.exe; Ant proxy settings are ignored; either url or srcFile is required.

param
url url to save

        wsdl.setUrl(url);
    
protected voidvalidate()
validation code

throws
BuildException if validation failed

        if (destFile == null) {
            throw new BuildException(ERROR_NO_DEST_FILE);
        }
        if (destFile.isDirectory()) {
            throw new BuildException(
                    ERROR_DEST_FILE_IS_DIR);
        }
        wsdl.validate();