处理来自 WCF 的未知肥皂消息
我有一个使用 SVCUTIL 从 C# .net 控制台应用程序中的 WSDL + XSD 生成的客户端。一切都很好,但出于某些逻辑错误处理的目的,客户端可能会收到一条响应消息,该消息未在 WSDL 中定义,因此需要进行反序列化和反序列化。将失败,但方法不会抛出异常但返回 null。
是否有任何通用方法来处理这种情况,或者我定义一个故障/错误消息 xsd(用于服务器返回的肥皂消息),并且在空响应的情况下,处理/反序列化该消息。
PS:我的远程服务无法抛出逻辑错误的故障异常。(是的,那里有点阻塞)。
I have a client generated using SVCUTIL from WSDL + XSD in C# .net console app. All fine but for some logical error handling purpose, client may receive a response message, which is not defined in WSDL hence deserialization & will fail but method does not throw exception but returns null.
Is there any generic way to handle this situation or I define a fault/error message xsd(for soap message returned by server) and in case of null response, handle/deserialize the message.
PS: My remote service can not throw a fault exception for logical errors.(yeah a bit of blockage there).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WSDL 是契约。这就像你有两个对象并在它们之间定义了接口一样。如果第一个对象调用第二个对象上的操作,则它期望返回由接口定义的值。如果我们使用某种非强类型语言,第二个对象将能够返回不同类型的返回值,而第一个对象将由于意外错误而失败。
编程语言有办法解决这个问题 - 在 .NET 中,您将使用
object
类型作为返回值,并且您始终必须手动调查您收到的类型以及如何处理返回值。对于 WCF,我们也有这样的高级类型 -System.ServiceModel.Channels.Message
但您确实不想使用它,因为在这种情况下您将必须手动构建 SOAP 请求并解析手动传入响应。作为 Web 服务中的旁注,单一请求类型始终具有单一响应类型和零个或多个错误类型(即 SOAP 错误)。如果您的服务对单个请求类型返回不同的响应类型,则此类服务不是“有效”的 Web 服务,并且无法通过 WSDL 进行描述。因此,它也不能以自动生成的 WCF 代理提供的强类型方式提供。
WSDL is contract. It is same like if you have two objects and defined interface between them. If the first object calls the operation on the second object it expects return value defined by interface. If we would use some non-strongly typed language the second object would be able to return different type of return value and the first object would fail because of unexpected error.
Programming languages have approach to solve this - in case of .NET you would use
object
type as return value and you would always have to manually investigate what type did you receive and how to handle the return value. In case of WCF we also have such high level type -System.ServiceModel.Channels.Message
but you really don't want to use it because in such case you will have to build SOAP request manually and parse incoming responses manually.As a side note in web services single request type has always single response type and zero or more error types (which are SOAP faults). If you have a service which returns different response types on single request type such service is not "valid" web service and cannot be described by WSDL. Because of that it also cannot be in strongly typed way provided by auto-generated WCF proxy.