C# and Web References

  • Thread starter Thread starter Holly
  • Start date Start date
H

Holly

Hi,

We have a web service that has mutliple levels; one for test, one for
QA and the other for production. With that, we also have one C#
component that accesses the web service depending on the level. What I
want to do is be able to compile the C# component once and have a
reference to all web services. There is code in the C# component to
indicate which web service to reference based on a registry setting.
However, the problem that I am having is that it fails to compile
because there are multiple instances to the same objects in the
different web references.

So, my question is: If I have the same web service setup in three
different locations knowing one is for testing, another for QA and
another for production how can I reference the ONE web reference I
need to use without having to compile it every time it moves to each
level?

Currently I have using statements setup to access each web reference.

Example Below:

using QAWebService;
using TestWebService;
using ProdWebService;

namespace Some.Namespace.Here
{
public class SomeClass
{
//
// Connect to the appropriate web service
//
switch (wsType)
{
case "TEST":
TestWebService webService = new TestWebService();
break;
case "QA":
QAWebService webService = new QAWebService();
break;
case "Prod":
ProdWebService webService = new ProdWebService();
break;
}

//
// Instantiate/Initialize a single request shared between
// each web service.
//
SomeRequest someReq = new SomeRequest();

someReq.Version = 1;
}
}

It fails compiling on the creation of "SomeRequest" because it is
ambiguous. Can anyone help?

Thanks,
Holly
 
Instead of setting a web reference, use wsdl.exe to create a proxy class
(this is basically what setting a web reference is doing for you). Then you
can modify the proxy class to decide at runtime which URL to hit based on
your registry key.

Or, look at the SoapHttpClientProtocol's Url property (the proxy class wsdl
generates derives from this) to set the Url at runtime.

Note that this assumes you have the same namespace for all three services
(that is, they are the same service on three different machines).
 
Back
Top