4

I have a web reference to web-service:

using (var client = new GetTemplateParamSoapClient("GetTemplateParamSoap"))
{
    TemplateParamsKeyValue[] responsArray = client.GetTemplatesParamsPerId(
        CtId, tempalteIds.ToArray());

    foreach (var pair in responsArray)
    {
        string value = FetchTemplateValue(pair.Key, pair.Value);
        TemplateComponentsData.Add(pair.Key, value);
    }
}

Tried to change a web-reference url from c# code: as advice here:

1) http://www.codeproject.com/KB/XML/wsdldynamicurl.aspx

2) How to call a web service with a configurable URL

3) http://aspalliance.com/283_Setting_Web_Service_References_Dynamically

But I get symbol is missing when trying to do:

client.Url

In addition I couldn't find a property of "Url_behavior"

Community
  • 1
  • 1
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • This is because you don't have a Web Reference, you have a Service Reference. That's a good thing, but the way to set the Url is different. – John Saunders Sep 27 '11 at 15:48
  • How do I do it, then? I don't have an option on right click "add web-reference" – Elad Benda Sep 27 '11 at 15:51
  • You don't want to use a web reference. Service Reference is the correct way to do it. I just don't have time to answer this morning. I'm sure someone will answer you shortly. In the meantime, maybe look at the different overloads of the constructor of your proxy class. – John Saunders Sep 27 '11 at 15:52
  • possible duplicate of [How to call a web service with a configurable url from a server side c# code?](http://stackoverflow.com/questions/7571253/how-to-call-a-web-service-with-a-configurable-url-from-a-server-side-c-code) – Alexei Levenkov Sep 27 '11 at 16:06

1 Answers1

6

It sounds like you've already added the service reference, but here's a walkthrough on adding, updating and removing service references.

Once you've got one of those in your project, you can alter the endpoint URI with one of the constructor overloads, as John Saunders said above. To do this, you'll need to know the name of the endpoint in your config file. For instance, after you add your service you might have elements like this in your config file:

<endpoint address="http://bleh.com/services/servicename.asmx"
    binding="basicHttpBinding" bindingConfiguration="ServiceNameSoap"
    contract="ServiceReference1.ServiceNameSoap" name="ServiceNameSoap" />

Given that endpoint, you can change the address at runtime by using the following overload:

var proxy = new ServiceReference1.ServiceNameSoapClient("ServiceNameSoap",
    "http://new-address.com/services/servicename.asmx");

You can also do it after construction, but that becomes a little bit harder. If you need to do so, see the documentation on the Endpoint property and the associated type ServiceEndpoint.

ladenedge
  • 13,197
  • 11
  • 60
  • 117