【问题标题】:Change service url?更改服务网址?
【发布时间】:2013-08-15 16:22:08
【问题描述】:

在我的 Web 应用程序中,我有一个服务引用(不是 Web 服务引用)。

[DebuggerStepThrough]
[GeneratedCode("System.ServiceModel", "4.0.0.0")]
public partial class LoginClient : ClientBase<Login.LoginClient>, Login.LoginSvc
{            
    public LoginClient() {
        EndpointAddress address = new EndpointAddress(ConfigurationManager.AppSettings["login_svc"]);
        this.Endpoint.Binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
        this.Endpoint.Address = address; 
    }
}

基本上,我在 AppSettings 中有“login_svc”。但是,它会引发流动异常:

我不想将服务配置添加到 web.config system.servicemodel....相反,我只想使用 url 的 appsettings。我该怎么做?

【问题讨论】:

  • 我相信像 this 这样的东西是你要找的。​​span>

标签: c# asp.net wcf service-reference


【解决方案1】:

与其尝试在构造函数中执行此操作,不如只使用在客户端应用程序中实例化代理时已经可用的重载构造函数之一。例如,

        MyService.Service1Client proxy = new MyService.Service1Client(
            new BasicHttpBinding(), 
            new EndpointAddress("<YOUR ENDPOINT ADDRESS>"));

此外,不建议像这样编辑自动生成的代码,因为如果您更新服务引用,那么这些更改将会丢失,因为此时会重新生成 Reference.cs 文件。当然,您可以复制 Reference.cs 并将其作为您自己管理的项目中的一个文件。不清楚你是否这样做,只是想提一下以防万一。

【讨论】:

    猜你喜欢
    • 2018-04-14
    • 1970-01-01
    • 2016-05-29
    • 2015-09-05
    • 1970-01-01
    • 2012-01-22
    • 2011-08-27
    • 2015-03-04
    • 2012-09-15
    相关资源
    最近更新 更多