locked
Change Service Reference Address Programmatically

    Question

  • I am writing a windows 8 app that will use a webservice to get data. all in c#. When A customer(company) purchases the app they will need to copy the webservice to their own web server than tell the app where their webservice is. I want to add a setup page where they can type in the address to their webservice and allow the program to use that address for the service reference. I can save the address they enter into an xml file and read the address from there but how do I get the service reference to use the address string received from the xml to find the webservice.
    Tuesday, March 3, 2015 9:59 PM

Answers

  • Hi PBPuddin,

    Are you using the WCF Service? If so I will recommand you use the ChannelFactory class to help us cosume the WCF Service in the Windows 8 app, in that way we can change the service address programmatically:

    BasicHttpBinding myBinding = new BasicHttpBinding();
    EndpointAddress myEndpoint = new EndpointAddress(yourserviceaddress);
    ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint); IService1 MyClient = myChannelFactory.CreateChannel();
    .......


    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by PBPuddin Wednesday, March 4, 2015 3:54 PM
    Wednesday, March 4, 2015 7:29 AM
    Moderator

All replies

  • Hi PBPuddin,

    Are you using the WCF Service? If so I will recommand you use the ChannelFactory class to help us cosume the WCF Service in the Windows 8 app, in that way we can change the service address programmatically:

    BasicHttpBinding myBinding = new BasicHttpBinding();
    EndpointAddress myEndpoint = new EndpointAddress(yourserviceaddress);
    ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint); IService1 MyClient = myChannelFactory.CreateChannel();
    .......


    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by PBPuddin Wednesday, March 4, 2015 3:54 PM
    Wednesday, March 4, 2015 7:29 AM
    Moderator
  • I am currently using a standard asp.net service with asmx file. however after doing some research online it sounds like I am better off using a WCF Service. So I will give this a try thanks.
    Wednesday, March 4, 2015 3:53 PM