生成了错误的SOAP请求

3
我使用这个答案生成了一个WSDL客户端。存根已成功生成,但当我调用服务器时出现以下错误消息。
undeclared namespace prefix SOAP-ENV at offset 216 of http://10.7.225.35:30002/kestrel/AirService

This is to stop the scroll bar obscuring the text 

当请求生成时,我可以看到目标命名空间被添加到body标签中,而不是soapEnvelope标签中。如果我手动更改并在SOAPUI工具中尝试它,它就像魅力一样工作。我也尝试从wsimport生成客户端,但出现了类似的问题。附上请求和响应以供参考。同时附上wsdl文件。
提前感谢您的帮助,任何帮助都将不胜感激。

Air WSDL文件

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="AirService"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:tns="http://www.travelport.com/service/air_v46_0"
             xmlns:ns1="http://www.travelport.com/schema/air_v46_0"
             targetNamespace="http://www.travelport.com/service/air_v46_0">

    <import namespace="http://www.travelport.com/service/air_v46_0"
          location="AirAbstract.wsdl" />

     <binding name="AirPrePayBinding"
             type="tns:AirPrePayPortType">
        <soap:binding style="document"
                      transport="http://schemas.xmlsoap.org/soap/http" />
        <operation name="service">
            <soap:operation soapAction="http://localhost:8080/kestrel/AirService"/>
                <input>
                    <soap:body use="literal" />
                </input>
                <output>
                    <soap:body use="literal" />
                </output>
                <fault name="ErrorInfoMsg">
                    <soap:fault name="ErrorInfoMsg" use="literal" />
                </fault>

        </operation>
    </binding>

AirAbstract.wsdl

<?xml version="1.0" encoding="UTF-8"?>

<definitions name="AirService"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:tns="http://www.travelport.com/service/air_v46_0"
             xmlns:ns1="http://www.travelport.com/schema/air_v46_0"
             targetNamespace="http://www.travelport.com/service/air_v46_0">

    <import namespace="http://www.travelport.com/service/air_v46_0"
          location="AirAbstract.wsdl" />

     <binding name="AirPrePayBinding"
             type="tns:AirPrePayPortType">
        <soap:binding style="document"
                      transport="http://schemas.xmlsoap.org/soap/http" />
        <operation name="service">
            <soap:operation soapAction="http://localhost:8080/kestrel/AirService"/>
                <input>
                    <soap:body use="literal" />
                </input>
                <output>
                    <soap:body use="literal" />
                </output>
                <fault name="ErrorInfoMsg">
                    <soap:fault name="ErrorInfoMsg" use="literal" />
                </fault>

        </operation>
    </binding>     

请求

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header />
    <S:Body xmlns:ns1="http://www.travelport.com/schema/air_v46_0" xmlns:ns2="http://www.travelport.com/schema/common_v46_0" xmlns:ns3="http://www.travelport.com/schema/vehicle_v46_0" xmlns:ns4="http://www.travelport.com/schema/rail_v46_0" xmlns:ns5="http://www.travelport.com/schema/cruise_v46_0" xmlns:ns6="http://www.travelport.com/schema/hotel_v46_0" xmlns:ns7="http://www.travelport.com/schema/passive_v46_0" xmlns:ns8="http://www.travelport.com/schema/universal_v46_0" xmlns:ns9="http://www.travelport.com/soa/common/security/SessionContext_v1">
        <ns1:LowFareSearchReq ReturnUpsellFare="true" TargetBranch="P7111432">
            <ns2:BillingPointOfSaleInfo OriginApplication="UAPI" />
            <ns1:SearchAirLeg>
                <ns1:SearchOrigin>
                    <ns2:CityOrAirport Code="BLR" />
                </ns1:SearchOrigin>
                <ns1:SearchDestination>
                    <ns2:CityOrAirport Code="JAI" />
                </ns1:SearchDestination>
                <ns1:SearchDepTime PreferredTime="2019-03-22" />
                <ns1:AirLegModifiers>
                    <ns1:PermittedCabins>
                        <ns2:CabinClass Type="Economy" />
                    </ns1:PermittedCabins>
                </ns1:AirLegModifiers>
            </ns1:SearchAirLeg>
            <ns1:AirSearchModifiers>
                <ns1:PreferredProviders>
                    <ns2:Provider Code="1G" />
                </ns1:PreferredProviders>
            </ns1:AirSearchModifiers>
            <ns2:SearchPassenger Code="ADT" />
            <ns2:SearchPassenger Code="INF" PricePTCOnly="true" />
            <ns2:SearchPassenger Code="CNN" />
            <ns1:AirPricingModifiers CurrencyType="INR" FaresIndicator="AllFares" />
        </ns1:LowFareSearchReq>
    </S:Body>
</S:Envelope>

响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <SOAP-ENV:faultcode>500</SOAP-ENV:faultcode>
            <SOAP-ENV:faultstring>undeclared namespace prefix SOAP-ENV at offset 216 of http://10.7.225.35:30002/kestrel/AirService</SOAP-ENV:faultstring>
            <SOAP-ENV:faultactor></SOAP-ENV:faultactor>
            <SOAP-ENV:detail>undeclared namespace prefix SOAP-ENV at offset 216 of http://10.7.225.35:30002/kestrel/AirService</SOAP-ENV:detail>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

请在您的问题中更新使用的CXF版本。并且,请更新您的WSDL文件,因为它们不完整。 - m4gic
cxf-codegen-plugin的版本是3.2.1,另外SO不允许我放置整个WSDL文件,您可以前往此链接https://support.travelport.com/webhelp/uapi/uAPI.htm#Resources/uAPI_WSDLschema_Release-V18.4.1.19.zip并下载整个集合,我正在尝试获取Air.wsdl、SharedBooking.wsdl和Universal.wsdl。 - Narendra Jaggi
1
我从你提供的网址下载了WSDLs。看起来他们发布了一个新版本(v47),我用它创建了一个模拟服务,并使用你的请求,更新了命名空间版本后,不论是否使用<SOAP-ENV>标记都能正常工作。然而,在下载的压缩包中,SessionContext命名空间周围存在一些错误。 - m4gic
你更新了哪个命名空间版本? - Narendra Jaggi
在uAPI_WSDLschema_Release-V18.4.1.19.zip文件中,CustomerProfileAbstract.wsdl文件中不存在SessionContext_v1_0命名空间,并且相关的导入声明(SessionContext_v1_0.xsd)也是错误的。但是在该zip文件中可以找到SessionContext_v1.xsd文件。 - m4gic
1个回答

0
在SOAP请求中,SOAP-ENV的命名空间是S命名空间的重复。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header />
    <S:Body xmlns:ns1="http://www.travelport.com/schema/air_v46_0" >

... snip ...

</S:Envelope>

我猜解析器不喜欢重复的命名空间前缀,所以将请求更改为使用S作为头的前缀(或者删除它,因为它没有被填充)。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" >    
    <S:Header />
    <S:Body xmlns:ns1="http://www.travelport.com/schema/air_v46_0" >

</S:Envelope>

关于其他命名空间,只要在使用之前声明它们,声明命名空间的位置应该不会影响文档。如果您发布由CXF生成的存根代码,我们可能可以识别出其中的问题。

重复出现的SOAP-ENV并不是问题的原因,在SOAP-UI中尝试时,如果将正文复制到信封标签中,则可以正常工作。另外,我想知道是否可以控制命名空间应出现的位置。 - Narendra Jaggi
有一个通过SOAP UI工作的请求示例吗?无论如何,如果问题出在生成的客户端上,那么请发布代码,这可能是一个简单的修复。 - stringy05
如果我从body标签中删除命名空间声明并将其添加到envelope标签中,我附加的请求将起作用。早些时候这是我的系统中生成请求的方式,然而在我的同事系统中生成了上述请求,因此它一直波动并且让人噩梦连连。 - Narendra Jaggi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接