Reputation: 57
I have a problem with updating dynamic Web Reference using WSDL.exe tool.
When I'm using "Update Web Reference" in VS, everything is working as expected.
Below is generated code (part of Reference.cs file):
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;
}
}
I'm getting necessary information from application properties which are then stored in config file and therefore can be changed without rebuilding application.
However when I use following command:
.\tools\wsdl.exe /l:cs /n:ServerReference /o".\ServerReference\Web References\Reference\Reference.cs" http://localhost:52956/MyService/MyService.asmx
it is created with fixed URL address in Reference.cs file.
Does anybody know how I should change my command to achieve the same Reference.cs file as in Visual Studio?
Upvotes: 1
Views: 1711
Reputation: 1921
I don't think you can generate the same code with wsdl.exe. But if the main thing you want to achieve is generating code that takes the service address from app.config then you can use wsdl.exe with the "/appsettingurlkey" switch.
The code you'll get will be something like this:
public WebService1() {
string urlSetting = System.Configuration.ConfigurationManager.AppSettings["ConfigKeyForServiceUrl"];
if ((urlSetting != null)) {
this.Url = urlSetting;
}
else {
this.Url = "http://localhost:65304/WebService1.asmx";
}
}
Be aware that it reads from 'appSettings' not from 'applicationSettings' through the Settings class, so you'll have to modify your app.config. And it doesn't contain the 'UseDefaultCredentials' stuff either.
Upvotes: 1