[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3503
  • Last Modified:

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

0
esko_user
Asked:
esko_user
1 Solution
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now