2012-01-22 47 views
0

我在使用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 
    } 
} 
+0

defectsservice.websi te.com/nameSurname將是一個很容易做... –

+0

@TonyHopkinson該服務不是我的,所以我不能改變它。 –

+0

啊,對不起,棒的結束。這應該有所幫助。 http://stackoverflow.com/questions/473028/how-to-edit-application-configuration-settings-app-config-best-way-to-go –

回答

0

如果我理解正確的話,在客戶端不斷變化的服務URL是很容易:

DefectsService.Defect defect = new DefectsService.Defect(); 
defect.Url = "theurlgoeshere"; 

(假設您的代理繼承自SoapHttpClientProtocol

+0

您的意思是我的代理從SoapHttpClientProtocol繼承。如何使它從SoapHttpClientProtocol繼承? –

+0

我更新了這個問題,這是你想到的嗎?這會工作嗎? –

+0

我的意思是'DefectsService.Defect'類。它是您的服務代理嗎?如果是這樣,它可能已經從提及的類繼承。 –

相關問題