简体   繁体   English

C#将SOAP请求重定向到另一个Web服务?

[英]C# Redirect SOAP request to another WebServices?

is it possible to build a web services (let's call it A) that can communicate with one or more webservices? 是否可以构建可以与一个或多个Web服务进行通信的Web服务(简称为A)?

kind of a SOAP proxy? 一种SOAP代理?

the webservice A will build it's functions based on other web service in server B and C Web服务A将基于服务器B和C中的其他Web服务来构建其功能

so clients will just send request to A and A will know here to send the request to (B or C) 因此客户只会将请求发送给A,而A会在此处知道将请求发送给(B或C)

is it possible to build such app? 有可能建立这样的应用程序吗?

Don't know if I understand your question the way it was meant, but it's possible to add a service reference to your webservice. 不知道我是否理解您的问题的含义,但是可以将服务引用添加到您的Web服务。 Which webservice to send the request to, you probably have to code ;-) 将请求发送到哪个Web服务,您可能必须编写代码;-)

If I understand correctly, you have 3 components in your app : 如果我理解正确,则您的应用程序中包含3个组件:

  • The client App 客户端应用
  • A "frontend" web service "WS A" “前端” Web服务“ WS A”
  • two other "backend" web services, "WS B" and "WS C" 另外两个“后端” Web服务,“ WS B”和“ WS C”

by frontend, I mean the web service is the only one exposed to the client, in other words a "facade". 所谓前端,是指Web服务是唯一公开给客户端的服务,换句话说就是“外观”。

If this is correct, you can reference the "WS B" and "WS C" from the "WS A" project. 如果正确,则可以从“ WS A”项目中引用“ WS B”和“ WS C”。 The code in the "WS A" can act as a client to these web services. “ WS A”中的代码可以充当这些Web服务的客户端。 This is often called an SOA architecture (service oriented architecture), where each service provides a functionnality, and can communicate with each others. 这通常称为SOA架构(面向服务的架构),其中每个服务都提供功能,并且可以彼此通信。

Thinks starts to be a bit difficult when you have infrastructures requirements (like delegating the client credentials), but I think it's the cleanest way to achieve what you want. 当您具有基础结构要求(例如委派客户端凭据)时,思考开始会有些困难,但是我认为这是实现所需目标的最干净的方法。

It's definitely possible and it's not something that lives or is bound to SOAP Web Services as this is an application implementation concern. 绝对有可能,并且它不是生存或绑定到SOAP Web Services的东西,因为这是应用程序实现的关注点。 What you should be more concerned with is how you are going to go about doing it. 您应该更加关心的是如何去做。

Using Data Transfer Objects 使用数据传输对象

Having spent many years developing Web Services I believe the best approach in the design of your web services is to follow Martin Fowler's DTO pattern where you communicate using remote-service-specific DTO's using a client proxy (aka Service Gateway) to the Web Service (aka Service Interface). 经过多年的Web服务开发工作,我相信设计Web服务的最佳方法是遵循Martin Fowler的DTO模式 ,在该模式下,您可以使用特定于远程服务的DTO,使用客户端代理 (也称为Service Gateway)与Web Service进行通信( aka服务接口)。 This 'message style' of web services is great from a Performance, SOA, re-usability point of view. 从性能,SOA,可重用性的角度来看,这种Web服务的“消息样式”非常有用。 Which forms the foundation of how my ServiceStack web services framework was built. 这构成了如何构建ServiceStack Web服务框架的基础。

The WCF RPC Approach WCF RPC方法

Unfortunately this best-practices convention is effectively discouraged by Microsoft's WCF SOAP Web Services framework as they encourage you to develop API-specific RPC method calls by insisting you to use method signatures to define your web services. 不幸的是,Microsoft的WCF SOAP Web服务框架实际上不鼓励使用此最佳实践约定,因为它们鼓励您通过坚持使用方法签名来定义Web服务来开发特定API的RPC方法调用 You can of course still develop 'message based' apis however it requires more effort to do so and is rarely demonstrated in their online tutorials. 您当然仍然可以开发“基于消息的” api,但是这样做需要更多的努力,并且很少在其在线教程中进行演示。 In my opinion this results in a client-specific API which encourages more remote method calls which as a result are less performant. 在我看来,这导致了特定于客户端的API,该API鼓励了更多的远程方法调用,从而降低了性能。 At times I really wish Microsoft would follow well established practices as published by industry experts instead of their often primary motivation of catering for drag-n-drop developers. 有时,我真的希望微软会遵循行业专家发布的成熟做法,而不是他们通常为拖拽开发人员服务的主要动机。

Calling multiple Web Services Asynchronously 异步调用多个Web服务

Going back to your original question you would define a web service that takes a request and if you're lucky that all your proxy web services share the same interface you should be able to use the same client proxy in a loop by changing the url for each service endpoint. 回到最初的问题,您将定义一个接受请求的Web服务,如果您很幸运所有代理Web服务共享相同的接口,则应该可以通过更改URL来在循环中使用相同的客户端代理 。每个服务端点。 I generally recommend that you fire each request off asynchronously (and join at the end) to speed up the execution time of your 'master web service'. 我通常建议您异步触发每个请求(并在最后加入),以加快 “主Web服务”的执行时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM