C# 如何使您的服务引用代理URL动态?

C# 如何使您的服务引用代理URL动态?,c#,wcf,wcf-client,C#,Wcf,Wcf Client,我有对web服务的web引用: using (var client = new GetTemplateParamSoapClient("GetTemplateParamSoap")) { TemplateParamsKeyValue[] responsArray = client.GetTemplatesParamsPerId( CtId, tempalteIds.ToArray()); foreach (var pair in responsArray)

我有对web服务的web引用:

using (var client = new GetTemplateParamSoapClient("GetTemplateParamSoap"))
{
    TemplateParamsKeyValue[] responsArray = client.GetTemplatesParamsPerId(
        CtId, tempalteIds.ToArray());

    foreach (var pair in responsArray)
    {
        string value = FetchTemplateValue(pair.Key, pair.Value);
        TemplateComponentsData.Add(pair.Key, value);
    }
}
尝试从c#code:更改web参考url,建议如下:

(一)

(二)

(三)

但我得到的符号在尝试执行以下操作时丢失:

client.Url

此外,我找不到“Url\u behavior”的属性。

听起来您已经添加了服务引用,但下面是有关的演练

一旦您的项目中有了其中一个,您就可以使用一个构造函数重载来更改端点URI,正如上面John Saunders所说的。为此,您需要知道配置文件中端点的名称。例如,添加服务后,您的配置文件中可能有如下元素:

<endpoint address="http://bleh.com/services/servicename.asmx"
    binding="basicHttpBinding" bindingConfiguration="ServiceNameSoap"
    contract="ServiceReference1.ServiceNameSoap" name="ServiceNameSoap" />

你也可以在施工后进行,但这会变得有点困难。如果需要,请参阅有关属性和关联类型的文档。

这是因为您没有Web引用,而是有服务引用。这是一件好事,但是设置Url的方法不同。那么我该怎么做呢?我没有右键单击“添加web引用”的选项您不想使用web引用。服务引用是正确的方法。今天早上我没时间回答。我相信很快会有人回答你的。同时,可以查看代理类的构造函数的不同重载
var proxy = new ServiceReference1.ServiceNameSoapClient("ServiceNameSoap",
    "http://new-address.com/services/servicename.asmx");