How to edit the endpoint address in reference.cs file?

Hello i have referred an web service in my client application and i want to change/override the endpoint address which is referenced. I was trying to specify the endpoint address in my reference.cs class but still this is not working. can anyone help me on this


regards
orginal reference.cs
 
public partial class HelloWorldClient : System.ServiceModel.ClientBase<sampleweb.ServiceReference1.HelloWorld>, sampleweb.ServiceReference1.HelloWorld {
        
        public HelloWorldClient() {
        }
        
        public HelloWorldClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }
        
        public HelloWorldClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public HelloWorldClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public HelloWorldClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }
 
I edited the web service address for this class as shown below,
 
public HelloWorldClient()
        {
        }
     //   new ServiceReference1.HelloWorldClient("HelloWorldSoapPort", "http://localhost:8080/ShowServiceA");
        public HelloWorldClient(string HelloWorldSoapPort) :
            base(HelloWorldSoapPort)
        {
        }
 
        public HelloWorldClient(string HelloWorldSoapPort, string remoteAddress) :
            base(HelloWorldSoapPort, "http://localhost:8080/ShowServiceA")
        {
        }
 
        public HelloWorldClient(string HelloWorldSoapPort, System.ServiceModel.EndpointAddress remoteAddress) :
            base(HelloWorldSoapPort, "http://localhost:8080/ShowServiceA")
        {
        }
 
        public HelloWorldClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
            base("HelloWorldSoapBinding", "http://localhost:8080/ShowServiceA")
        {
        }

Open in new window

esko_userAsked:
Who is Participating?
 
ripahoratiuCommented:
You shouldn't do that....
Basically the generated proxy (reference.cs) should not be modified. The address is basically read from app.config file and is usually set to localhost - where you can change it if you want to.
But if you want to modify it on the fly, programatically, the best choice is to modify it via the exposed properties of System.Web.Services.Protocols.SoapHttpClientProtocol (or whatever is the base class for your service in reference.cs).

I mean you can do, when you instantiate the service:

MyService serviceProxy = new MyService();
serviceProxy.Url = "http://... the new endpoint you want ...     ";
.... call methods

and that will direct your calls to the new endpoint. Of course you must have at that endpoint the service and the types and the methods with the same signature.




0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.