单独的Web服务环境 [英] Separate web service environments

查看:88
本文介绍了单独的Web服务环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是WCF的新手,所以我想在设计一个Web服务客户端时要求一些指导。



目标Web服务有四种不同的环境 - 系统测试,集成测试,验收测试和生产。对于所有不同的环境,API都完全相同。我的应用程序的用户应该能够选择要使用的环境。在我的VS项目中,我已经为所有四个环境WSDL添加了一个服务引用:



问题。由于所有环境都使用相同的API但具有不同的端点,我是否可以在实际Web服务调用中的端点之间切换?我不想为此编写四种不同的方法(构建soap请求的代码很多......)。

Hi,

I''m new to WCF, and so I would like to ask for some guidelines in designing a web service client.

The target web service has four different environments - system test, integration test, acceptance test and production. The API is exactly the same for all different environments. The user of my application should be able to select what environment to use. In my VS project I have added a service reference to all four environment WSDL:s.

To the question. Since all environments use the same API but with different endpoints, is there any way I can switch between the endpoints in the actual web service call? I don''t want to write four different methods for this(building the soap request is a lot of code...).

//Declare the service envelope
SYS_TEST.ServiceEnvelope serviceEnvelope = new ServiceEnvelope ();
serviceEnvelope.Password = "xxx"
//lots of code filling up the request goes here...
SYS_TEST.CalculateXXClient client = new CalculateXXClient();
//Send the request
client.calculateXX(ref serviceEnvelope);

推荐答案

你应该有1项服务如果API相同则引用。只需根据您选择的环境以编程方式更改端点



You should have 1 service reference if the APIs are the same. Just programmatically change the endpoint depending on your chosen environment

var uri = new Uri("Your URL for the environment");
service = new ServiceClient();
service.Endpoint.Address = new System.ServiceModel.EndpointAddress(url);


这篇关于单独的Web服务环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆