SOAP Web服务:许多服务器,一个接口

时间:2022-10-21 22:49:58

I have a scenario in which I'm going to need an arbitrary number of servers to provide the same SOAP web service. I would like to generate one set of proxy classes and be able to supply them with a location to point them at the different servers at runtime. Unfortunately, it looks as though the wsdl:port node (child of wsdl:service) requires the address of a specific server to be hardcoded. It appears that due to this the URL will be baked into my proxy classes. I know that I could potentially modify this by hand-editing the generated proxy classes, or modifying the code generation, but I'd really prefer not to resort to that. I feel like there's got to be a better way to solve this problem. I just want to decouple the interface definition from the location that the service will be residing at. I'm using VS2008 and C#.NET if that's of any help though best would be a language-agnostic (SOAP or WSDL specific) general solution to this problem.

我有一个场景,我将需要任意数量的服务器来提供相同的SOAP Web服务。我想生成一组代理类,并能够为它们提供一个位置,以便在运行时将它们指向不同的服务器。不幸的是,看起来好像wsdl:port节点(wsdl:service的子节点)需要硬编码特定服务器的地址。看来,由于这个原因,URL将被烘焙到我的代理类中。我知道我可以通过手工编辑生成的代理类或修改代码生成来修改它,但我真的不想诉诸于此。我觉得必须有一个更好的方法来解决这个问题。我只想将接口定义与服务所在的位置分离。我正在使用VS2008和C#.NET,如果有任何帮助,尽管最好的是与语言无关(SOAP或WSDL特定)这个问题的一般解决方案。

8 个解决方案

#1


2  

Why don't you load balance the web servers and then create a DNS entry for the load balanced IP address....essentially creating a web farm. This will allow you to reference the hostname rather than the static IP addresses and if you ever need to change the IP address of the load balancer or the web servers it is a one time change. Plus you then have redundancy and performance control.

为什么不对Web服务器进行负载平衡,然后为负载均衡的IP地址创建DNS条目....实质上是创建Web场。这将允许您引用主机名而不是静态IP地址,如果您需要更改负载均衡器或Web服务器的IP地址,则这是一次性更改。此外,您还可以进行冗余和性能控制。

#2


2  

If you're using a WebReference (pre-WCF) to get to the web service, you can simply set the Url property on the web service proxy class after you create it.

如果您使用WebReference(pre-WCF)访问Web服务,则只需在创建Web服务代理类后在Web服务代理类上设置它。

For WCF, you can provide a different endpoint address to the proxy class constructor, rather than using the default (among other possible solutions).

对于WCF,您可以为代理类构造函数提供不同的端点地址,而不是使用缺省值(以及其他可能的解决方案)。

#3


2  

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

不,在.NET中,您可以在运行时更改URL。

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

#4


0  

When you add a web reference to your project, it places the address of the web service into the .config file of your application / web application. You can then simply change this setting in the config file to point to a different web service location, assuming of course that the services are identical.

向项目添加Web引用时,会将Web服务的地址放入应用程序/ Web应用程序的.config文件中。然后,您可以简单地在配置文件中更改此设置以指向不同的Web服务位置,当然假设服务是相同的。

#5


0  

The easiest solution would be to use a software load balancer such as HAProxy. At more cost, you could use a hardware solution such as Big-IP.

最简单的解决方案是使用软件负载平衡器,如HAProxy。以更高的成本,您可以使用Big-IP等硬件解决方案。

#6


0  

Here's a hint on how to decide the URL of WSDL. I´m just changing the port but it´s of course possible to make it more advanced.

这是关于如何确定WSDL的URL的提示。我只是在改变端口,但它当然可以使它更先进。

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 that in your Add_Code and add the following reference to your web.config.

将它放在Add_Code中,并将以下引用添加到web.config中。

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

I hope you can get new ideas of this.

我希望你能得到新的想法。

#7


0  

Client proxies have URL property you can set at runtime. To make it simpler, wsdl.exe utility has /appsettingurlkey key. When you generate a client proxy, it's constructor will check the key in appSettings and set the service URL accordingly. I believe WCF has this feature as well.

客户端代理具有您可以在运行时设置的URL属性。为了简化,wsdl.exe实用程序具有/ appsettingurlkey密钥。当您生成客户端代理时,它的构造函数将检查appSettings中的密钥并相应地设置服务URL。我相信WCF也有这个功能。

However, I would agree with @Matt and suggest you consider load balancing as the best solution in the long run.

但是,我同意@Matt并建议您从长远来看将负载平衡视为最佳解决方案。

#8


0  

  1. Is this for scaling (each server provides the same data) or
  2. 这是用于扩展(每个服务器提供相同的数据)或

  3. for same API different data on each server?
  4. 对于每个服务器上相同的API不同的数据?

For 2, then you can do as above, just change the service URL in code.

对于2,您可以执行上述操作,只需更改代码中的服务URL即可。

For 1, you could use round-robin DNS (e.g. you see multiple servers with at the command line type nslookup www.google.com).

对于1,您可以使用循环DNS(例如,您在命令行中看到多个服务器类型为nslookup www.google.com)。

#1


2  

Why don't you load balance the web servers and then create a DNS entry for the load balanced IP address....essentially creating a web farm. This will allow you to reference the hostname rather than the static IP addresses and if you ever need to change the IP address of the load balancer or the web servers it is a one time change. Plus you then have redundancy and performance control.

为什么不对Web服务器进行负载平衡,然后为负载均衡的IP地址创建DNS条目....实质上是创建Web场。这将允许您引用主机名而不是静态IP地址,如果您需要更改负载均衡器或Web服务器的IP地址,则这是一次性更改。此外,您还可以进行冗余和性能控制。

#2


2  

If you're using a WebReference (pre-WCF) to get to the web service, you can simply set the Url property on the web service proxy class after you create it.

如果您使用WebReference(pre-WCF)访问Web服务,则只需在创建Web服务代理类后在Web服务代理类上设置它。

For WCF, you can provide a different endpoint address to the proxy class constructor, rather than using the default (among other possible solutions).

对于WCF,您可以为代理类构造函数提供不同的端点地址,而不是使用缺省值(以及其他可能的解决方案)。

#3


2  

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

不,在.NET中,您可以在运行时更改URL。

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

#4


0  

When you add a web reference to your project, it places the address of the web service into the .config file of your application / web application. You can then simply change this setting in the config file to point to a different web service location, assuming of course that the services are identical.

向项目添加Web引用时,会将Web服务的地址放入应用程序/ Web应用程序的.config文件中。然后,您可以简单地在配置文件中更改此设置以指向不同的Web服务位置,当然假设服务是相同的。

#5


0  

The easiest solution would be to use a software load balancer such as HAProxy. At more cost, you could use a hardware solution such as Big-IP.

最简单的解决方案是使用软件负载平衡器,如HAProxy。以更高的成本,您可以使用Big-IP等硬件解决方案。

#6


0  

Here's a hint on how to decide the URL of WSDL. I´m just changing the port but it´s of course possible to make it more advanced.

这是关于如何确定WSDL的URL的提示。我只是在改变端口,但它当然可以使它更先进。

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 that in your Add_Code and add the following reference to your web.config.

将它放在Add_Code中,并将以下引用添加到web.config中。

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

I hope you can get new ideas of this.

我希望你能得到新的想法。

#7


0  

Client proxies have URL property you can set at runtime. To make it simpler, wsdl.exe utility has /appsettingurlkey key. When you generate a client proxy, it's constructor will check the key in appSettings and set the service URL accordingly. I believe WCF has this feature as well.

客户端代理具有您可以在运行时设置的URL属性。为了简化,wsdl.exe实用程序具有/ appsettingurlkey密钥。当您生成客户端代理时,它的构造函数将检查appSettings中的密钥并相应地设置服务URL。我相信WCF也有这个功能。

However, I would agree with @Matt and suggest you consider load balancing as the best solution in the long run.

但是,我同意@Matt并建议您从长远来看将负载平衡视为最佳解决方案。

#8


0  

  1. Is this for scaling (each server provides the same data) or
  2. 这是用于扩展(每个服务器提供相同的数据)或

  3. for same API different data on each server?
  4. 对于每个服务器上相同的API不同的数据?

For 2, then you can do as above, just change the service URL in code.

对于2,您可以执行上述操作,只需更改代码中的服务URL即可。

For 1, you could use round-robin DNS (e.g. you see multiple servers with at the command line type nslookup www.google.com).

对于1,您可以使用循环DNS(例如,您在命令行中看到多个服务器类型为nslookup www.google.com)。