Domanda

In my web application, I have a service reference (not web service reference).

[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; 
    }
}

Basically, I have the "login_svc" in the AppSettings. However, it throws the flowing exception:

I don't want to add the service configuration to the web.config system.servicemodel....instead I just want to use the appsettings for the url. How do I do this?

È stato utile?

Soluzione

Rather than trying to do this in the constructor, you should just use one of the overloaded constructors already available to you when you instantiate the proxy in your client application. For example,

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

Also, it's not recommended to edit the auto-generated code like this because if you update your service reference, then those changes will be lost because the Reference.cs file is regenerated at that time. Of course, you could copy the Reference.cs and make it a file in your project you manage as one of your own. It's not clear if you were doing that or not but just wanted to mention this just in case.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top