【发布时间】:2012-02-16 04:27:11
【问题描述】:
我正在 Visual Studio 中创建一个使用 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 并且他的服务将被使用。如我所见,解决方案中唯一写入 URL 的地方是 app.config 文件。但是,如果我转到“显示所有文件”,则会出现更多带有 URL 的文件,例如 configuration.svcinfo、References.cs 等。所以,我有一个问题:
在我的解决方案中,我在 URL 中添加了带有我的姓名和姓氏的服务。如果我保持这样(添加的服务)并且当用户输入他的 URL 时,我只更改 app.config 文件,上面的代码会像他的服务一样工作,而不是我的吗?或者不是,因为在我添加它时服务已经有了我的 URL?
更新
根据 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.website.com/nameSurname 会容易很多...
-
@TonyHopkinson 该服务不是我的,所以我无法更改。
-
啊,抱歉弄错了。这应该会有所帮助。 stackoverflow.com/questions/473028/…
-
@TonyHopkinson 我听不懂你。这是否意味着您的第一条评论不是针对我的问题?
-
是的 tt 的意思是我误解了你的问题。
标签: visual-studio