简体   繁体   English

使用不正确的wsdl访问SOAP Web服务

[英]Accessing SOAP web service with incorrect wsdl

Background: 背景:

I need to consume an existing web service (SOAP over http) that has a couple of issues: 我需要使用一个存在两个问题的现有Web服务(基于HTTP的SOAP):

1) The wsdl on the server doesn't even resemble the web service as described in their documentation, which includes a completely different wsdl file 1)服务器上的wsdl甚至不像其文档中描述的Web服务那样,其中包括完全不同的wsdl文件

2) The wsdl file provided with their documentation seems to come close to describing the web service on the server, but when I generated java client code using cxf and used it to access the web service, cxf throws exceptions like the following 2)他们的文档提供的wsdl文件似乎很接近描述服务器上的Web服务,但是当我使用cxf生成Java客户端代码并将其用于访问Web服务时,cxf会引发如下异常

 javax.xml.bind.UnmarshalException: unexpected element (uri:"http://us-labs.companyxyz.com/", local:"searchResponse"). Expected elements are <{http://companyxyz.com/xyz-xml/2.0/}searchResponse>
... 33 more

I'm no SOAP expert, but assuming this means the namespaces in their response don't match those defined in the wsdl. 我不是SOAP专家,但是假设这意味着响应中的名称空间与wsdl中定义的名称空间不匹配。

Since my application is written in java, I was able to connect and get a response using commons http client and a handcrafted SOAP request, so worst case I can fall back to that and parse the response to get what I need. 由于我的应用程序是用Java编写的,因此我可以使用commons http客户端和手工制作的SOAP请求进行连接并获得响应,因此,最坏的情况是我可以回过头来解析响应以获取所需的信息。

My questions: 我的问题:

  1. Did I interpret the exception correctly? 我是否正确解释了异常?
  2. If no: any suggestions on how I can debug this? 如果否:关于如何调试此方法的任何建议?
  3. If yes: can anyone suggest better alternatives to handcrafting http requests and parsing xml by hand? 如果是:有人可以提出更好的替代方法来手工制作http请求和手动解析xml吗? (Getting correct wsdl is, unfortunately, not an option) (不幸的是,获得正确的wsdl并不是一种选择)

Thanks in advance. 提前致谢。

  1. Most likely. 最有可能的。 The response is using the namespace "http://us-labs.companyxyz.com/", but in the WSDL, the same element is declared with namespace "http://companyxyz.com/xyz-xml/2.0/". 响应使用名称空间“ http://us-labs.companyxyz.com/”,但是在WSDL中,使用名称空间“ http://companyxyz.com/xyz-xml/2.0/”声明了相同的元素。

  2. I'm not familiar with CXF, but other SOAP frameworks usually offer some kind of logging capabilities. 我不熟悉CXF,但是其他SOAP框架通常提供某种日志记录功能。 It would probably help you if the SOAP requests and responses are logged somewhere for more specific analysis. 如果将SOAP请求和响应记录在某处进行更具体的分析,则可能会对您有所帮助。

  3. Why is it not an option to get a correct WSDL? 为什么没有选择正确的WSDL? If you really are able to "handcraft" correct SOAP requests and expect to be able to "handparse" the responses, you should be able to write the WSDL yourself as well. 如果您确实能够“手工”处理正确的SOAP请求,并且希望能够“处理”响应,那么您也应该可以自己编写WSDL。 Of course, the WSDL should be provided to you by the service operator, but if you mean that noone is able to provide you with a correct WSDL, I would consider writing it myself instead of creating and parsing the SOAP messages manually. 当然,应该由服务运营商为您提供WSDL,但是如果您的意思是没有人能够为您提供正确的WSDL,那么我将考虑自己编写它,而不是手动创建和解析SOAP消息。

I think you interpreted the exception correctly - the namespace is different than expected. 我认为您正确解释了该异常-名称空间与预期的有所不同。

It is also not really unexpected. 这也不是真正出乎意料的。 it is a fact of life that vendor supplied wsdls are not always correct. 现实生活中,供应商提供的wsdl并不总是正确的。 We actually write our own WSDLs and XSDs for vendor applications for just that reason. 正因为如此,我们实际上为供应商应用程序编写了自己的WSDL和XSD。

You can use your own WSDL even run-time. 您甚至可以在运行时使用自己的WSDL。 There are some SO questions on that, here and here . 这里这里都有一些SO问题。

You could also have a look here . 您也可以在这里看看。 I haven't tried it, but it could work. 我还没有尝试过,但是可以用。

We actually extend the generated service and create a port supplying a WSDL located on the classpath using the JaxWS Service constructor . 实际上,我们使用JaxWS Service构造函数扩展了生成的服务,并创建了一个提供位于类路径上的WSDL的端口。 That works fine for us. 这对我们来说很好。

We debug CXF by dumping the incoming and outgoing messages. 我们通过转储传入和传出消息来调试CXF。 There seem to be quite a lot of methods to do just that. 似乎有很多方法可以做到这一点。 We use either a proxy between de web service and our client, or recently a cxf.xml file somewhere. 我们在Web服务和客户端之间使用代理,或者最近在某处使用cxf.xml文件。 Using a -D flag we temprarily configure this. 使用-D标志,我们临时配置它。

-Dcxf.config.file=/home/me/cxf-debug.xml 

and cxf-debug.xml contains something like : 和cxf-debug.xml包含如下内容

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:cxf="http://cxf.apache.org/core"
      xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <cxf:bus>
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus> 
</beans>

http://cxf.apache.org/docs/debugging-and-logging.html http://cxf.apache.org/docs/debugging-and-logging.html

Both responses suggested the same basic approach, which turned out to be the correct one. 两种回应都提出了相同的基本方法,事实证明这是正确的方法。 I fixed the provided wsdl to make it match the web service, and I was able to use cxf, which saved me a lot of hand coding. 我修复了提供的wsdl以使其与Web服务匹配,并且能够使用cxf,这为我节省了很多手工编码。

The main problem with their wsdl was in fact a namespace issue. 他们的wsdl的主要问题实际上是名称空间问题。 The essence of the problem was as follows: their wsdl defined two namespaces, both of which have a "searchResponse" element. 问题的实质如下:它们的wsdl定义了两个名称空间,两个名称空间均具有“ searchResponse”元素。

{http://us-labs.companyxyz.com/}searchResponse

was defined in the wsdl to contain 0 or more 在wsdl中定义为包含0或更多

{http://companyxyz.com/xyz-xml/2.0/}searchResponse

But in their response the nested searchResponse wasn't qualified by {http://companyxyz.com/xyz-xml/2.0/} so cxf interpreted it as a {http://us-labs.companyxyz.com/}searchResponse 但是在他们的响应中,嵌套的searchResponse没有被{http://companyxyz.com/xyz-xml/2.0/}限定,因此cxf将其解释为{http://us-labs.companyxyz.com/}searchResponse

I fixed it by introducing a new type. 我通过引入一种新类型来修复它。

Thanks to both responders. 感谢两位响应者。

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

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