【Webサービス】【WSDL】WSDLファイルからC#/VB etc のソースを抽出する

■ 手順

例 : 「C:\sample\sampleWsdlFile.wsdl」から CSファイル を抽出する

Visual Studio C++ 2008 Express を使っている場合
 [1] [スタート]-[すべてのプログラム]-[Microsoft Visual Studio C++ 2008 Express Edition]
      -[Visual Studio Tools]-[Visual Studio 2008 コマンドプロンプト]を選択

 [2] WSDLファイルのあるパスまで「cd」で移動
  ~~~~
   cd C:\sample
  ~~~~

 [3] 以下のコマンドを入力する(★ここ注目★)
  ~~~~
   wsdl /l:CS sampleWsdlFile.wsdl
  ~~~~

   ※注意 「CS」は必ず大文字であること!!

■ 構文

ヘルプ

wsdl /?

指定のフォルダ内にソースを格納する

例:フォルダ「outFolder」内に格納する

wsdl /l:CS /o:outFolder sampleWsdlFile.wsdl

他のプログラム言語のソースを抽出する

VB
wsdl /l:VB sampleWsdlFile.wsdl
JavaScript
wsdl /l:JS sampleWsdlFile.wsdl
C++(ヘッダーファイル。*.h)
wsdl /l:CPP sampleWsdlFile.wsdl

※注意 ヘルプをみて、「VJS」ってあったので、試しにやってみたらダメでした

■ サンプル

WSDL(入力)

sampleWsdlFile.wsdl
<?xml version="1.0"?>
<definitions
   name="SampleService"
   targetNamespace="http://www.bea.com/wls90"
   xmlns:tns="http://www.bea.com/wls90"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns="http://schemas.xmlsoap.org/wsdl/" >
        <message name="getSampleRequest">
                <part name="zip" type="xsd:string"/>
        </message>
        <message name="getSampleResponse">
                <part name="return" type="xsd:float"/>
        </message>
        <portType name="SampleType">
                <operation name="getSample">
                        <input message="tns:getSampleRequest"/>
                        <output message="tns:getSampleResponse"/>
                </operation>
        </portType>
        <binding name="SampleBinding" type="tns:SampleType">
                <soap:binding style="rpc" 
                             transport="">http://schemas.xmlsoap.org/soap/http"/>
                <operation name="getSample">
                        <soap:operation soapAction=""/>
                        <input>
                                <soap:body use="literal"
                                 namespace="http://www.bea.com/wls90" />
                        </input>
                        <output>
                                <soap:body use="literal"
                                 namespace="http://www.bea.com/wls90" />
                        </output>
                </operation>
        </binding>
        <service name="SampleService">
            <documentation>This is a Sample</documentation>
            <port name="SamplePort" binding="tns:SampleBinding">
               <soap:address 
                          location="">http://localhost:7001/Sample/SampleService"/>
            </port>
        </service>
</definitions>

CSファイル(出力結果)

SampleService.cs
//------------------------------------------------------------------------------
// <auto-generated>
//     このコードはツールによって生成されました。
//     ランタイム バージョン:2.0.50727.3649
//
//     このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
//     コードが再生成されるときに損失したりします。
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

// 
// This source code was auto-generated by wsdl, Version=2.0.50727.1432.
// 


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="SampleBinding", Namespace="http://www.bea.com/wls90")]
public partial class SampleService : System.Web.Services.Protocols.SoapHttpClientProtocol {
    
    private System.Threading.SendOrPostCallback getSampleOperationCompleted;
    
    /// <remarks/>
    public SampleService() {
        this.Url = "http://localhost:7001/Sample/SampleService";
    }
    
    /// <remarks/>
    public event getSampleCompletedEventHandler getSampleCompleted;
    
    /// <remarks/>
    [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://www.bea.com/wls90", ResponseNamespace="http://www.bea.com/wls90", Use=System.Web.Services.Description.SoapBindingUse.Literal)]
    [return: System.Xml.Serialization.XmlElementAttribute("return")]
    public float getSample(string zip) {
        object[] results = this.Invoke("getSample", new object[] {
                    zip});
        return ((float)(results[0]));
    }
    
    /// <remarks/>
    public System.IAsyncResult BegingetSample(string zip, System.AsyncCallback callback, object asyncState) {
        return this.BeginInvoke("getSample", new object[] {
                    zip}, callback, asyncState);
    }
    
    /// <remarks/>
    public float EndgetSample(System.IAsyncResult asyncResult) {
        object[] results = this.EndInvoke(asyncResult);
        return ((float)(results[0]));
    }
    
    /// <remarks/>
    public void getSampleAsync(string zip) {
        this.getSampleAsync(zip, null);
    }
    
    /// <remarks/>
    public void getSampleAsync(string zip, object userState) {
        if ((this.getSampleOperationCompleted == null)) {
            this.getSampleOperationCompleted = new System.Threading.SendOrPostCallback(this.OngetSampleOperationCompleted);
        }
        this.InvokeAsync("getSample", new object[] {
                    zip}, this.getSampleOperationCompleted, userState);
    }
    
    private void OngetSampleOperationCompleted(object arg) {
        if ((this.getSampleCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.getSampleCompleted(this, new getSampleCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }
    
    /// <remarks/>
    public new void CancelAsync(object userState) {
        base.CancelAsync(userState);
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")]
public delegate void getSampleCompletedEventHandler(object sender, getSampleCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class getSampleCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    
    private object[] results;
    
    internal getSampleCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
            base(exception, cancelled, userState) {
        this.results = results;
    }
    
    /// <remarks/>
    public float Result {
        get {
            this.RaiseExceptionIfNecessary();
            return ((float)(this.results[0]));
        }
    }
}