tags:

views:

35

answers:

3

Hi.

So, i have a central web service that is responsible for managing other services. These services register in the main WS with their URL, leading to their own web service.

what i need to do now is call the child web services from the central web service. I've searched google on how to do this but all i could find was this.

I would like to register any web service and not create a web reference, as suggested in the solution i've found.

How is this done without using a web reference?

A: 

Alka,

if you are using webservices, other than WCF, you can change the URL of the webservice you are going to in the web.config, you can also change this in code via the URL on your proxy.

eg

 var testuri = "http://a_web_server/PostCode1/PostCodeWebService.asmx";
 proxy.Url = testuri;

You could also create your own webservice proxy and handle the webservice redirection from there.

Iain
Thanks for the quick answer. Although i'm still confused about this - do i have to create a web reference to the services to do what you said?
Alka
you would do with the above solution, if you look at the web reference code, you will find a file called reference.cs which is the code that the webservice uses, if you want to create your own webservice proxy its a good starting point.
Iain
A: 

You probably could add a web reference when developing (that will allow visual studio to discover the web service and have a working Intellisense).

In your code however, you can create the object dynamically.

Say you need to use an object called TestSoapClient to access your web service. If you want to create it with the URL from the web reference, you would just do

TestSoapClient testSoapClient = new TestSoapClient();

That code would use the default URL (i.e. the one that you pointed to when you added your web reference).

If you want to create the TestSoapClient object dynamically using a URL that you specify at runtime, go with something like this :

        XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
        readerQuotas.MaxDepth = 32;
        readerQuotas.MaxStringContentLength = 8192;
        readerQuotas.MaxArrayLength = 16384;
        readerQuotas.MaxBytesPerRead = 4096;
        readerQuotas.MaxNameTableCharCount = 16384;

        BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
        basicHttpBinding.Name = BindingName;
        basicHttpBinding.CloseTimeout = new TimeSpan(0, 1, 0);
        basicHttpBinding.OpenTimeout = new TimeSpan(0, 1, 0);
        basicHttpBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
        basicHttpBinding.SendTimeout = new TimeSpan(0, 1, 0);
        basicHttpBinding.AllowCookies = false;
        basicHttpBinding.BypassProxyOnLocal = false;
        basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        basicHttpBinding.MaxBufferSize = 65536;
        basicHttpBinding.MaxBufferPoolSize = 524288;
        basicHttpBinding.MaxReceivedMessageSize = 65536;
        basicHttpBinding.MessageEncoding = WSMessageEncoding.Text;
        basicHttpBinding.TextEncoding = Encoding.UTF8;
        basicHttpBinding.TransferMode = TransferMode.Buffered;
        basicHttpBinding.UseDefaultWebProxy = true;
        basicHttpBinding.ReaderQuotas = readerQuotas;
        basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
        basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

        EndpointAddress endpointAddress = new EndpointAddress("YourDynamicUrl");

        TestSoapClient testSoapClient = new TestSoapClient(basicHttpBinding, endpointAddress);

That way the value of the web reference URL and the values in the config file won't be used at runtime.

Hugo Migneron
A: 

Ok, problem solved.

My solution to this was using a web reference and change the proxy URL to the service i want. This way i can dynamically access my web services.

Thanks for your answers.

Alka