SOAP Web Service: Multiple Servers, One Interface

I have a scenario in which I need an arbitrary number of servers to provide the same SOAP web service. I would like to create one set of proxy classes and be able to tell them the location to point them to different servers at runtime. Unfortunately, it looks like wsdl:portnode (a childwsdl:service) requires that the address of a specific server be hard-coded. It seems that because of this, the URL will be baked into my proxy classes. I know that I can change this manually by editing the generated proxy classes or by changing the code generation, but I would prefer not to resort to this. I feel that there should be a better way to solve this problem. I just want to separate the interface definition from the location where the service will be located. I am using VS2008 and C # .NET if there would be any help, although it would be best to be a language agnostic (SOAP agent or WSDL) to solve this problem.

+2
source share
8 answers

No, in .NET you can change the url at runtime.

Service svc = new Service ();
svc.url = "Value read from config. file or some such"
output = svc.method (input);
+2

WebReference (pre-WCF) -, Url - - .

WCF , ( ).

+2

-, DNS IP-.... -. , IP-, - IP- -, . , .

+2

- , - .config /-. , -, , .

0

- URL, . , wsdl.exe /appsettingurlkey. , appSettings URL- . , WCF .

@Matt .

0
  • ( )
  • API ?

2, , , URL- .

1 DNS (, nslookup www.google.com).

0

- , ​​ HAProxy. , Big-IP.

0

, URL- WSDL. , , , .

public class PortChangeReflector : SoapExtensionReflector
{     
    public override void ReflectDescription()
    {
        ServiceDescription description = ReflectionContext.ServiceDescription;
        foreach (Service service in description.Services)
        {
            foreach (Port port in service.Ports)
            {
                foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                {
                    SoapAddressBinding binding = extension as SoapAddressBinding;
                    if (binding != null && !binding.Location.Contains("8092"))
                    {
                        binding.Location = binding.Location.Replace("92", "8092");
                    }
                }
            }
        }
    }
}

Put this in Add_Codeyours and add the following link to your web.config.

<webServices>
     <soapExtensionReflectorTypes>
          <add type="Dev.PortChangeReflector,App_Code"/>
     </soapExtensionReflectorTypes>
</webServices>

Hope you can get some new ideas.

0
source

All Articles