简体   繁体   English

如何忽略SOAP响应中的不可用字段

[英]How to Ignore unavailable fields from a SOAP Response

I have a web service developed in SOAP, for which a client is generated already. 我有一个用SOAP开发的Web服务,已经为其生成了一个客户端。 Now I am adding a new field in response of web service. 现在我正在添加一个新的字段来响应Web服务。 Now when I am invoking the client it gives error as the updated field is not available in Data Class available at client side.Is there any way to Ignore those property which are not available in data class while unmarshaling. 现在,当我调用客户端时,它会给出错误,因为更新的字段在客户端可用的数据类中不可用。有没有办法忽略那些在解组时在数据类中不可用的属性。 the same works fine in REST. 同样在REST中工作正常。 TIA TIA

This works in REST because with HTTP only you don't have such a strict protocol of communication as it is with SOAP over HTTP . 这在REST有效,因为只有HTTP才能与SOAP over HTTP一样具有如此严格的通信协议。 In SOAP a more restrictive and detailed technical contract is in place by default and both sides must comply with it. SOAP中,默认情况下制定了更严格和详细的技术合同,双方必须遵守该合同。 If you want the same behavior of REST you'd have to implement validation and rules yourself since it is a bit open and that is part a of the idea. 如果你想要REST的相同行为,你必须自己实现验证和规则,因为它有点开放 ,这是想法的一部分。

To solve your issue, you'll probably need to regenerate your client proxy/stub class, using the new WSDL file in order to make the client aware that a new field have been added and could be expected in the response of the server. 要解决您的问题,您可能需要使用新的WSDL文件重新生成客户端代理/存根类,以使客户端知道已添加新字段并且可以在服务器的响应中预期。 You can also add this field manually to the response in your current stub class and mark it as optional, without using any of the auto-generating tools. 您也可以手动将此字段添加到当前存根类中的响应中,并将其标记为可选,而不使用任何自动生成工具。

If you want to avoid breaking clients altogether (and regenerating/modifying classes) when you introduce changes in the future, you may try: 如果您希望在将来引入更改时完全避免破坏客户端(并重新生成/修改类),您可以尝试:

  1. Creating new service version for new consumers, maintaining both - old and new version, making the new available only to new consumers; 为新消费者创建新的服务版本,维护旧版本和新版本,使新版本仅供新消费者使用;
  2. Creating a new service operation for new consumers in the same service, maintaining both - old and new operation, making the new available only to new consumers; 为同一服务中的新消费者创建新的服务操作,维护新旧操作,使新服务仅供新消费者使用;
  3. Mark fields as optional - attribute minOccurs=0 in the WSDL (only possible when this is allowed by your use case). 将字段标记为可选 - WSDL中的属性minOccurs=0 (仅当您的用例允许时才可以)。 See XML Schema Indicators . 请参阅XML架构指示器 In short in your WSDL, your element must look something like this: <xs:element name="el_name" type="xs:string" minOccurs="0" maxOccurs="1"/> . 简而言之,在您的WSDL中,您的元素必须如下所示: <xs:element name="el_name" type="xs:string" minOccurs="0" maxOccurs="1"/> Try this way, without updating the contract at client side. 尝试这种方式,而无需在客户端更新合同。 Again, it depends on how strict the client is about following the contract. 同样,这取决于客户遵守合同的严格程度。
  4. Try and see if there are any specific options in Java to make the client more tolerant to optional values - for example - this one )* 尝试查看Java中是否有任何特定选项使客户端更容忍可选值 - 例如 - 这一个 )*

These approaches are useful if you have many clients you cannot modify and you do not want to break communication contract with them. 如果您有许多无法修改的客户端并且您不希望与它们断开通信合同,则这些方法很有用。 Be aware that all the above options come at a cost - you'll trade more maintenance and governance on your side for increased compatibility with clients. 请注意,以上所有选项都需要付出代价 - 您将为您提供更多维护和管理,以提高与客户的兼容性。 So choose wisely. 所以明智地选择。

Hope this helps! 希望这可以帮助!

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

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