1


WSDL.exe ツールを使用して動的 Web 参照を更新する際に問題があります。

VS で「Web 参照の更新」を使用している場合、すべてが期待どおりに機能しています。以下は、生成されたコード (Reference.cs ファイルの一部) です。

    public MyService() {
        this.Url = global::ServerReference.Properties.Settings.Default.ServerReference_Reference_MyService;
        if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
            this.UseDefaultCredentials = true;
            this.useDefaultCredentialsSetExplicitly = false;
        }
        else {
            this.useDefaultCredentialsSetExplicitly = true;
        }
    }

アプリケーションのプロパティから必要な情報を取得しています。この情報は構成ファイルに保存されるため、アプリケーションを再構築せずに変更できます。

ただし、次のコマンドを使用すると:

.\tools\wsdl.exe /l:cs /n:ServerReference /o".\ServerReference\Web References\Reference\Reference.cs" http://localhost:52956/MyService/MyService.asmx

Reference.cs ファイルに固定の URL アドレスで作成されます。

Visual Studioと同じReference.csファイルを実現するためにコマンドを変更する方法を知っている人はいますか?

4

1 に答える 1

1

wsdl.exe で同じコードを生成できるとは思えません。ただし、達成したい主な目的が app.config からサービス アドレスを取得するコードを生成することである場合は、「/appsettingurlkey」スイッチを指定して wsdl.exe を使用できます。

取得するコードは次のようになります。

public WebService1() {
    string urlSetting = System.Configuration.ConfigurationManager.AppSettings["ConfigKeyForServiceUrl"];
    if ((urlSetting != null)) {
        this.Url = urlSetting;
    }
    else {
        this.Url = "http://localhost:65304/WebService1.asmx";
    }
}

Settings クラスを介して「applicationSettings」からではなく「appSettings」から読み取ることに注意してください。そのため、app.config を変更する必要があります。また、「UseDefaultCredentials」も含まれていません。

于 2013-03-20T10:28:55.983 に答える