2012-01-22 51 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'类。它是您的服务代理吗?如果是这样,它可能已经从提及的类继承。 –

相关问题