2013-03-20 38 views
1


我在使用WSDL.exe工具更新動態Web引用時遇到問題。通過命令行更新動態Web引用(wsdl工具)

當我在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文件?

回答

1

我不認爲你可以用wsdl.exe生成相同的代碼。 但是,如果您想實現的主要目標是生成代碼,該代碼需要從app.config獲取服務地址,那麼您可以將wsdl.exe與「/ appsettingurlkey」開關一起使用。

你得到的將是這樣的代碼:

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

要知道,它通過設置類「的appSettings」不「的applicationSettings」讀,所以你必須修改的app.config。它也不包含'UseDefaultCredentials'。