我在使用Web引用的Visual Studio中創建應用程序。爲參考的網址是:爲每個用戶提供不同URL的Web服務引用
https://nameSurname.website.com/defectsservice.asmx
這是我如何使用它在我的代碼:
DefectsService.Defect defect = new DefectsService.Defect();
defect.Name = mo.DefectName;
defect.DateFound = DateTime.Now;
noDefect = new DefectsService.DefectHandler().AddDefect(mo.Guid, defect);
//DefectsService is the name of the service which I give when I add the reference
我需要這樣的應用程序:用戶將進入他的網址和他服務將被使用。正如我所看到的,唯一將URL寫入解決方案的地方是在app.config文件中。但是,如果我去'顯示所有文件',那麼會出現更多帶有URL的文件,例如config.svcinfo,References.cs等等。所以,我有一個問題:
在我的解決方案中,我添加了服務我的名字和姓氏在URL中。如果我像這樣(添加服務)離開它,並且當用戶輸入他的URL時,我只更改app.config文件,上面的代碼是否會像他的服務一樣工作,而不是我的服務?或者不是,因爲當我添加它時服務已經有了我的URL?
UPDATE
這裏是Wiktor的Zychla的建議後,我的代碼:
class Program : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public Program()
{
this.Url = "";//url entered from every user
}
static void Main(string[] args)
{
DefectsService.Defect d = new DefectsService.Defect();
defect.Name = mo.DefectName;
defect.DateFound = DateTime.Now;
noDefect = new DefectsService.DefectHandler().AddDefect(mo.Guid, defect);
//DefectsService is the name of the service which I give when I add the reference
}
}
defectsservice.websi te.com/nameSurname將是一個很容易做... –
@TonyHopkinson該服務不是我的,所以我不能改變它。 –
啊,對不起,棒的結束。這應該有所幫助。 http://stackoverflow.com/questions/473028/how-to-edit-application-configuration-settings-app-config-best-way-to-go –