3

我正在尝试使用 JAX-WS 连接到 Web 服务,它的 WSDL 定义与从 Web 服务接收到的实际响应不完全匹配。基本上,WSDL 表明所有元素都是“urn:HPD_IncidentInterface_WS”名称空间的一部分,但实际响应元素位于“urn:Port”名称空间中。这会导致 JAX-WS 抛出以下异常:

com.sun.xml.internal.ws.streaming.XMLStreamReaderException:意外的 XML 标记。预期:{urn:HPD_IncidentInterface_WS}HelpDesk_QueryList_ServiceResponse 但发现:{urn:Port}HelpDesk_QueryList_ServiceResponse

我解决此问题的计划是下载 WSDL,修改它以匹配实际响应中的命名空间,然后使用 wsimport 重新生成 JAX-WS 代码。但是,我很难弄清楚如何修改 WSDL 以使响应命名空间正确。根据我到目前为止的研究,看起来我需要使用包含 urn:Port targetNamespace 的 wsdl:definition 创建一个新的 WSDL 文件,然后将其导入原始 WSDL 文件,但我不能似乎语法正确。谁能帮我更正 WSDL 以匹配实际的 Web 服务响应?

以下是引用urn:Port命名空间的响应示例:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns0:HelpDesk_QueryList_ServiceResponse xmlns:ns0="urn:Port">
         <ns0:getListValues>
            <ns0:Assigned_Group>APP-eBiz-EP-L2</ns0:Assigned_Group>
            <ns0:Assigned_Group_Shift_Name/>
            <ns0:Assigned_Support_Company>Acme</ns0:Assigned_Support_Company>
            <ns0:Assigned_Support_Organization>Applications - eBusinessServices</ns0:Assigned_Support_Organization>
            <ns0:Assignee>Geoff Denning</ns0:Assignee>
            <ns0:Categorization_Tier_1>Issue</ns0:Categorization_Tier_1>
            <ns0:Categorization_Tier_2>Failure</ns0:Categorization_Tier_2>
            <ns0:Categorization_Tier_3/>
            <ns0:City>Mountain View</ns0:City>
            <ns0:Closure_Manufacturer/>
            <ns0:Closure_Product_Category_Tier1/>
            <ns0:Closure_Product_Category_Tier2/>
            <ns0:Closure_Product_Category_Tier3/>
            <ns0:Closure_Product_Model_Version/>
            <ns0:Closure_Product_Name/>
            <ns0:Company>Acme</ns0:Company>
            <ns0:Contact_Company>Acme</ns0:Contact_Company>
            <ns0:Contact_Sensitivity>Standard</ns0:Contact_Sensitivity>
            <ns0:Country>United States</ns0:Country>
            <ns0:Department>Mgmt Information Systems</ns0:Department>
            <ns0:Summary>Test summary</ns0:Summary>
            <ns0:Notes>Refer to the attached error screenshot.</ns0:Notes>
            <ns0:First_Name>Geoff</ns0:First_Name>
            <ns0:Impact>4-Minor/Localized</ns0:Impact>
            <ns0:Incident_Number>INC000000773346</ns0:Incident_Number>
            <ns0:Internet_E-mail>geoff@acme.com</ns0:Internet_E-mail>
            <ns0:Last_Name>Denning</ns0:Last_Name>
            <ns0:Manufacturer/>
            <ns0:Middle_Initial/>
            <ns0:Organization>IT-eBusiness</ns0:Organization>
            <ns0:Phone_Number>000-0000</ns0:Phone_Number>
            <ns0:Priority>Low</ns0:Priority>
            <ns0:Priority_Weight>2</ns0:Priority_Weight>
            <ns0:Product_Categorization_Tier_1>Software-Application</ns0:Product_Categorization_Tier_1>
            <ns0:Product_Categorization_Tier_2>eBusiness Services</ns0:Product_Categorization_Tier_2>
            <ns0:Product_Categorization_Tier_3>Test</ns0:Product_Categorization_Tier_3>
            <ns0:Product_Model_Version/>
            <ns0:Product_Name/>
            <ns0:Region>Americas</ns0:Region>
            <ns0:Reported_Source>Email</ns0:Reported_Source>
            <ns0:Resolution/>
            <ns0:Resolution_Category/>
            <ns0:Resolution_Category_Tier_2/>
            <ns0:Resolution_Category_Tier_3/>
            <ns0:Service_Type>User Service Restoration</ns0:Service_Type>
            <ns0:Site>Mountain View, CA</ns0:Site>
            <ns0:Site_Group>NA West</ns0:Site_Group>
            <ns0:Status>Assigned</ns0:Status>
            <ns0:Status_Reason/>
            <ns0:Urgency>4-Low</ns0:Urgency>
            <ns0:VIP>No</ns0:VIP>
         </ns0:getListValues>
      </ns0:HelpDesk_QueryList_ServiceResponse>
   </soapenv:Body>
</soapenv:Envelope>

仅具有命名空间的现有 WSDL urn:HPD_IncidentInterface_WS

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:HPD_IncidentInterface_WS" xmlns:s0="urn:HPD_IncidentInterface_WS" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <wsdl:types>
  <xsd:schema elementFormDefault="qualified" targetNamespace="urn:HPD_IncidentInterface_WS">
   <xsd:element name="HelpDesk_Query_Service" type="s0:GetInputMap"/>
   <xsd:complexType name="GetInputMap">
    <xsd:sequence>
     <xsd:element name="Incident_Number" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="HelpDesk_Query_ServiceResponse" type="s0:GetOutputMap"/>
   <xsd:complexType name="GetOutputMap">
    <xsd:sequence>
     <xsd:element name="Assigned_Group" type="xsd:string"/>
     <xsd:element name="Assigned_Group_Shift_Name" type="xsd:string"/>
     <xsd:element name="Assigned_Support_Company" type="xsd:string"/>
     <xsd:element name="Assigned_Support_Organization" type="xsd:string"/>
     <xsd:element name="Assignee" type="xsd:string"/>
     <xsd:element name="Categorization_Tier_1" type="xsd:string"/>
     <xsd:element name="Categorization_Tier_2" type="xsd:string"/>
     <xsd:element name="Categorization_Tier_3" type="xsd:string"/>
     <xsd:element name="City" type="xsd:string"/>
     <xsd:element name="Closure_Manufacturer" type="xsd:string"/>
     <xsd:element name="Closure_Product_Category_Tier1" type="xsd:string"/>
     <xsd:element name="Closure_Product_Category_Tier2" type="xsd:string"/>
     <xsd:element name="Closure_Product_Category_Tier3" type="xsd:string"/>
     <xsd:element name="Closure_Product_Model_Version" type="xsd:string"/>
     <xsd:element name="Closure_Product_Name" type="xsd:string"/>
     <xsd:element name="Company" type="xsd:string"/>
     <xsd:element name="Contact_Company" type="xsd:string"/>
     <xsd:element name="Contact_Sensitivity" type="s0:Contact_SensitivityType"/>
     <xsd:element name="Country" type="xsd:string"/>
     <xsd:element name="Department" type="xsd:string"/>
     <xsd:element name="Summary" type="xsd:string"/>
     <xsd:element name="Notes" type="xsd:string"/>
     <xsd:element name="First_Name" type="xsd:string"/>
     <xsd:element name="Impact" type="s0:ImpactType"/>
     <xsd:element name="Last_Name" type="xsd:string"/>
     <xsd:element name="Manufacturer" type="xsd:string"/>
     <xsd:element name="Middle_Initial" type="xsd:string"/>
     <xsd:element name="Organization" type="xsd:string"/>
     <xsd:element name="Phone_Number" type="xsd:string"/>
     <xsd:element name="Priority" type="s0:PriorityType"/>
     <xsd:element name="Priority_Weight" type="xsd:int"/>
     <xsd:element name="Product_Categorization_Tier_1" type="xsd:string"/>
     <xsd:element name="Product_Categorization_Tier_2" type="xsd:string"/>
     <xsd:element name="Product_Categorization_Tier_3" type="xsd:string"/>
     <xsd:element name="Product_Model_Version" type="xsd:string"/>
     <xsd:element name="Product_Name" type="xsd:string"/>
     <xsd:element name="Region" type="xsd:string"/>
     <xsd:element name="Reported_Source" type="s0:Reported_SourceType"/>
     <xsd:element name="Resolution" type="xsd:string"/>
     <xsd:element name="Resolution_Category" type="xsd:string"/>
     <xsd:element name="Resolution_Category_Tier_2" type="xsd:string"/>
     <xsd:element name="Resolution_Category_Tier_3" type="xsd:string"/>
     <xsd:element name="Service_Type" type="s0:Service_TypeType"/>
     <xsd:element name="Site" type="xsd:string"/>
     <xsd:element name="Site_Group" type="xsd:string"/>
     <xsd:element name="Status" type="s0:StatusType"/>
     <xsd:element name="Status_Reason" type="s0:Status_ReasonType"/>
     <xsd:element name="Urgency" type="s0:UrgencyType"/>
     <xsd:element name="VIP" type="s0:VIPType"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:simpleType name="Contact_SensitivityType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Sensitive"/>
     <xsd:enumeration value="Standard"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="ImpactType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="1-Extensive/Widespread"/>
     <xsd:enumeration value="2-Significant/Large"/>
     <xsd:enumeration value="3-Moderate/Limited"/>
     <xsd:enumeration value="4-Minor/Localized"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="PriorityType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Critical"/>
     <xsd:enumeration value="High"/>
     <xsd:enumeration value="Medium"/>
     <xsd:enumeration value="Low"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="Reported_SourceType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Direct Input"/>
     <xsd:enumeration value="Email"/>
     <xsd:enumeration value="External Escalation"/>
     <xsd:enumeration value="Fax"/>
     <xsd:enumeration value="Systems Management"/>
     <xsd:enumeration value="Phone"/>
     <xsd:enumeration value="Voice Mail"/>
     <xsd:enumeration value="Walk In"/>
     <xsd:enumeration value="Web"/>
     <xsd:enumeration value="Other"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="Service_TypeType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="User Service Restoration"/>
     <xsd:enumeration value="User Service Request"/>
     <xsd:enumeration value="Infrastructure Restoration"/>
     <xsd:enumeration value="Infrastructure Event"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="StatusType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="New"/>
     <xsd:enumeration value="Assigned"/>
     <xsd:enumeration value="In Progress"/>
     <xsd:enumeration value="Pending"/>
     <xsd:enumeration value="Resolved"/>
     <xsd:enumeration value="Closed"/>
     <xsd:enumeration value="Cancelled"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="Status_ReasonType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Infrastructure Change Created"/>
     <xsd:enumeration value="Local Site Action Required"/>
     <xsd:enumeration value="Purchase Order Approval"/>
     <xsd:enumeration value="Registration Approval"/>
     <xsd:enumeration value="Supplier Delivery"/>
     <xsd:enumeration value="Support Contact Hold"/>
     <xsd:enumeration value="Third Party Vendor Action Reqd"/>
     <xsd:enumeration value="Client Action Required"/>
     <xsd:enumeration value="Infrastructure Change"/>
     <xsd:enumeration value="Request"/>
     <xsd:enumeration value="Future Enhancement"/>
     <xsd:enumeration value="Pending Original Incident"/>
     <xsd:enumeration value="Client Hold"/>
     <xsd:enumeration value="Monitoring Incident"/>
     <xsd:enumeration value="Customer Follow-Up Required"/>
     <xsd:enumeration value="Temporary Corrective Action"/>
     <xsd:enumeration value="No Further Action Required"/>
     <xsd:enumeration value="Resolved by Original Incident"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="UrgencyType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="1-Critical"/>
     <xsd:enumeration value="2-High"/>
     <xsd:enumeration value="3-Medium"/>
     <xsd:enumeration value="4-Low"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="VIPType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Yes"/>
     <xsd:enumeration value="No"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:element name="HelpDesk_QueryList_Service" type="s0:GetListInputMap"/>
   <xsd:complexType name="GetListInputMap">
    <xsd:sequence>
     <xsd:element name="Qualification" type="xsd:string"/>
     <xsd:element name="startRecord" type="xsd:string"/>
     <xsd:element name="maxLimit" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="HelpDesk_QueryList_ServiceResponse" type="s0:GetListOutputMap"/>
   <xsd:complexType name="GetListOutputMap">
    <xsd:sequence>
     <xsd:element maxOccurs="unbounded" name="getListValues">
      <xsd:complexType>
       <xsd:sequence>
        <xsd:element name="Assigned_Group" type="xsd:string"/>
        <xsd:element name="Assigned_Group_Shift_Name" type="xsd:string"/>
        <xsd:element name="Assigned_Support_Company" type="xsd:string"/>
        <xsd:element name="Assigned_Support_Organization" type="xsd:string"/>
        <xsd:element name="Assignee" type="xsd:string"/>
        <xsd:element name="Categorization_Tier_1" type="xsd:string"/>
        <xsd:element name="Categorization_Tier_2" type="xsd:string"/>
        <xsd:element name="Categorization_Tier_3" type="xsd:string"/>
        <xsd:element name="City" type="xsd:string"/>
        <xsd:element name="Closure_Manufacturer" type="xsd:string"/>
        <xsd:element name="Closure_Product_Category_Tier1" type="xsd:string"/>
        <xsd:element name="Closure_Product_Category_Tier2" type="xsd:string"/>
        <xsd:element name="Closure_Product_Category_Tier3" type="xsd:string"/>
        <xsd:element name="Closure_Product_Model_Version" type="xsd:string"/>
        <xsd:element name="Closure_Product_Name" type="xsd:string"/>
        <xsd:element name="Company" type="xsd:string"/>
        <xsd:element name="Contact_Company" type="xsd:string"/>
        <xsd:element name="Contact_Sensitivity" type="s0:Contact_SensitivityType"/>
        <xsd:element name="Country" type="xsd:string"/>
        <xsd:element name="Department" type="xsd:string"/>
        <xsd:element name="Summary" type="xsd:string"/>
        <xsd:element name="Notes" type="xsd:string"/>
        <xsd:element name="First_Name" type="xsd:string"/>
        <xsd:element name="Impact" type="s0:ImpactType"/>
        <xsd:element name="Incident_Number" type="xsd:string"/>
        <xsd:element name="Internet_E-mail" type="xsd:string"/>
        <xsd:element name="Last_Name" type="xsd:string"/>
        <xsd:element name="Manufacturer" type="xsd:string"/>
        <xsd:element name="Middle_Initial" type="xsd:string"/>
        <xsd:element name="Organization" type="xsd:string"/>
        <xsd:element name="Phone_Number" type="xsd:string"/>
        <xsd:element name="Priority" type="s0:PriorityType"/>
        <xsd:element name="Priority_Weight" type="xsd:int"/>
        <xsd:element name="Product_Categorization_Tier_1" type="xsd:string"/>
        <xsd:element name="Product_Categorization_Tier_2" type="xsd:string"/>
        <xsd:element name="Product_Categorization_Tier_3" type="xsd:string"/>
        <xsd:element name="Product_Model_Version" type="xsd:string"/>
        <xsd:element name="Product_Name" type="xsd:string"/>
        <xsd:element name="Region" type="xsd:string"/>
        <xsd:element name="Reported_Source" type="s0:Reported_SourceType"/>
        <xsd:element name="Resolution" type="xsd:string"/>
        <xsd:element name="Resolution_Category" type="xsd:string"/>
        <xsd:element name="Resolution_Category_Tier_2" type="xsd:string"/>
        <xsd:element name="Resolution_Category_Tier_3" type="xsd:string"/>
        <xsd:element name="Service_Type" type="s0:Service_TypeType"/>
        <xsd:element name="Site" type="xsd:string"/>
        <xsd:element name="Site_Group" type="xsd:string"/>
        <xsd:element name="Status" type="s0:StatusType"/>
        <xsd:element name="Status_Reason" type="s0:Status_ReasonType"/>
        <xsd:element name="Urgency" type="s0:UrgencyType"/>
        <xsd:element name="VIP" type="s0:VIPType"/>
       </xsd:sequence>
      </xsd:complexType>
     </xsd:element>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="HelpDesk_Modify_Service" type="s0:SetInputMap"/>
   <xsd:complexType name="SetInputMap">
    <xsd:sequence>
     <xsd:element name="Categorization_Tier_1" type="xsd:string"/>
     <xsd:element name="Categorization_Tier_2" type="xsd:string"/>
     <xsd:element name="Categorization_Tier_3" type="xsd:string"/>
     <xsd:element name="Closure_Manufacturer" type="xsd:string"/>
     <xsd:element name="Closure_Product_Category_Tier1" type="xsd:string"/>
     <xsd:element name="Closure_Product_Category_Tier2" type="xsd:string"/>
     <xsd:element name="Closure_Product_Category_Tier3" type="xsd:string"/>
     <xsd:element name="Closure_Product_Model_Version" type="xsd:string"/>
     <xsd:element name="Closure_Product_Name" type="xsd:string"/>
     <xsd:element name="Company" type="xsd:string"/>
     <xsd:element name="Summary" type="xsd:string"/>
     <xsd:element name="Notes" type="xsd:string"/>
     <xsd:element name="Impact" type="s0:ImpactType"/>
     <xsd:element name="Manufacturer" type="xsd:string"/>
     <xsd:element name="Product_Categorization_Tier_1" type="xsd:string"/>
     <xsd:element name="Product_Categorization_Tier_2" type="xsd:string"/>
     <xsd:element name="Product_Categorization_Tier_3" type="xsd:string"/>
     <xsd:element name="Product_Model_Version" type="xsd:string"/>
     <xsd:element name="Product_Name" type="xsd:string"/>
     <xsd:element name="Reported_Source" type="s0:Reported_SourceType"/>
     <xsd:element name="Resolution" type="xsd:string"/>
     <xsd:element name="Resolution_Category" type="xsd:string"/>
     <xsd:element name="Resolution_Category_Tier_2" type="xsd:string"/>
     <xsd:element name="Resolution_Category_Tier_3" type="xsd:string"/>
     <xsd:element name="Resolution_Method" type="xsd:string"/>
     <xsd:element name="Service_Type" type="s0:Service_TypeType"/>
     <xsd:element name="Status" type="s0:StatusType"/>
     <xsd:element name="Urgency" type="s0:UrgencyType"/>
     <xsd:element name="Action" type="xsd:string"/>
     <xsd:element name="Work_Info_Summary" type="xsd:string"/>
     <xsd:element name="Work_Info_Notes" type="xsd:string"/>
     <xsd:element name="Work_Info_Type" type="s0:Work_Info_TypeType"/>
     <xsd:element name="Work_Info_Date" type="xsd:dateTime"/>
     <xsd:element name="Work_Info_Source" type="s0:Work_Info_SourceType"/>
     <xsd:element name="Work_Info_Locked" type="s0:VIPType"/>
     <xsd:element name="Work_Info_View_Access" type="s0:Work_Info_View_AccessType"/>
     <xsd:element name="Incident_Number" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:simpleType name="Work_Info_TypeType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="----- Customer Inbound -----"/>
     <xsd:enumeration value="Customer Communication"/>
     <xsd:enumeration value="Customer Follow-up"/>
     <xsd:enumeration value="Customer Status Update"/>
     <xsd:enumeration value="----- Customer Outbound -----"/>
     <xsd:enumeration value="Closure Follow Up"/>
     <xsd:enumeration value="Detail Clarification"/>
     <xsd:enumeration value="General Information"/>
     <xsd:enumeration value="Resolution Communications"/>
     <xsd:enumeration value="Satisfaction Survey"/>
     <xsd:enumeration value="Status Update"/>
     <xsd:enumeration value="----- General -----"/>
     <xsd:enumeration value="Incident Task / Action"/>
     <xsd:enumeration value="Problem Script"/>
     <xsd:enumeration value="Working Log"/>
     <xsd:enumeration value="Email System"/>
     <xsd:enumeration value="Paging System"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="Work_Info_SourceType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Email"/>
     <xsd:enumeration value="Fax"/>
     <xsd:enumeration value="Phone"/>
     <xsd:enumeration value="Voice Mail"/>
     <xsd:enumeration value="Walk In"/>
     <xsd:enumeration value="Pager"/>
     <xsd:enumeration value="System Assignment"/>
     <xsd:enumeration value="Web"/>
     <xsd:enumeration value="Other"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="Work_Info_View_AccessType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Internal"/>
     <xsd:enumeration value="Public"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:element name="HelpDesk_Modify_ServiceResponse" type="s0:SetOutputMap"/>
   <xsd:complexType name="SetOutputMap">
    <xsd:sequence/>
   </xsd:complexType>
   <xsd:element name="AuthenticationInfo" type="s0:AuthenticationInfo"/>
   <xsd:complexType name="AuthenticationInfo">
    <xsd:sequence>
     <xsd:element name="userName" type="xsd:string"/>
     <xsd:element name="password" type="xsd:string"/>
     <xsd:element minOccurs="0" name="authentication" type="xsd:string"/>
     <xsd:element minOccurs="0" name="locale" type="xsd:string"/>
     <xsd:element minOccurs="0" name="timeZone" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
  </xsd:schema>
 </wsdl:types>

   <wsdl:message name="HelpDesk_Query_ServiceSoapIn">

      <wsdl:part element="s0:HelpDesk_Query_Service" name="parameters"/>

   </wsdl:message>

   <wsdl:message name="HelpDesk_Query_ServiceSoapOut">

      <wsdl:part element="s0:HelpDesk_Query_ServiceResponse" name="parameters"/>

   </wsdl:message>

   <wsdl:message name="HelpDesk_Modify_ServiceSoapIn">

      <wsdl:part element="s0:HelpDesk_Modify_Service" name="parameters"/>

   </wsdl:message>

   <wsdl:message name="HelpDesk_Modify_ServiceSoapOut">

      <wsdl:part element="s0:HelpDesk_Modify_ServiceResponse" name="parameters"/>

   </wsdl:message>

   <wsdl:message name="HelpDesk_QueryList_ServiceSoapOut">

      <wsdl:part element="s0:HelpDesk_QueryList_ServiceResponse" name="parameters"/>

   </wsdl:message>

   <wsdl:message name="HelpDesk_QueryList_ServiceSoapIn">

      <wsdl:part element="s0:HelpDesk_QueryList_Service" name="parameters"/>

   </wsdl:message>

   <wsdl:message name="ARAuthenticate">

      <wsdl:part element="s0:AuthenticationInfo" name="parameters"/>

   </wsdl:message>

   <wsdl:portType name="HPD_IncidentInterface_WSPortType">

      <wsdl:operation name="HelpDesk_Query_Service">

         <wsdl:input message="s0:HelpDesk_Query_ServiceSoapIn"/>

         <wsdl:output message="s0:HelpDesk_Query_ServiceSoapOut"/>

      </wsdl:operation>

      <wsdl:operation name="HelpDesk_QueryList_Service">

         <wsdl:input message="s0:HelpDesk_QueryList_ServiceSoapIn"/>

         <wsdl:output message="s0:HelpDesk_QueryList_ServiceSoapOut"/>

      </wsdl:operation>

      <wsdl:operation name="HelpDesk_Modify_Service">

         <wsdl:input message="s0:HelpDesk_Modify_ServiceSoapIn"/>

         <wsdl:output message="s0:HelpDesk_Modify_ServiceSoapOut"/>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="HPD_IncidentInterface_WSSoapBinding" type="s0:HPD_IncidentInterface_WSPortType">

      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="HelpDesk_Query_Service">

         <soap:operation soapAction="urn:HPD_IncidentInterface_WS/HelpDesk_Query_Service" style="document"/>

         <wsdl:input>

            <soap:header message="s0:ARAuthenticate" part="parameters" use="literal">

            </soap:header>

            <soap:body use="literal"/>

         </wsdl:input>

         <wsdl:output>

            <soap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="HelpDesk_QueryList_Service">

         <soap:operation soapAction="urn:HPD_IncidentInterface_WS/HelpDesk_QueryList_Service" style="document"/>

         <wsdl:input>

            <soap:header message="s0:ARAuthenticate" part="parameters" use="literal">

            </soap:header>

            <soap:body use="literal"/>

         </wsdl:input>

         <wsdl:output>

            <soap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="HelpDesk_Modify_Service">

         <soap:operation soapAction="urn:HPD_IncidentInterface_WS/HelpDesk_Modify_Service" style="document"/>

         <wsdl:input>

            <soap:header message="s0:ARAuthenticate" part="parameters" use="literal">

            </soap:header>

            <soap:body use="literal"/>

         </wsdl:input>

         <wsdl:output>

            <soap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="HPD_IncidentInterface_WSService">

  <wsdl:documentation>
Query and Modify Operations  </wsdl:documentation>

      <wsdl:port binding="s0:HPD_IncidentInterface_WSSoapBinding" name="HPD_IncidentInterface_WSSoap">

         <soap:address location="http://internal.acme.com:8080/arsys/services/ARService?server=rsm7&amp;webService=HPD_IncidentInterface_WS"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>
4

1 回答 1

7

感谢SoapHandlersOsw提供的提示,我能够解决这个问题。这是我的解决方法,以防有人遇到类似情况:

1) 向您的主要 JAX-WS 服务类添加处理程序链注释:@HandlerChain(file = "handlers.xml")

2) 将 handlers.xml 文件添加到资源文件夹:

<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
    <handler-chain>
        <handler>
            <handler-class>com.sample.handlers.FixNamespaceHandler
            </handler-class>
        </handler>
    </handler-chain>
</handler-chains>

3) 添加 FixNamespaceHandler 用正确的命名空间声明替换不正确的命名空间声明:

public class FixNamespaceHandler implements SOAPHandler<SOAPMessageContext> {

    @Override
    public void close(MessageContext arg0) {
        // Do nothing
    }

    @Override
    public boolean handleFault(SOAPMessageContext arg0) {
        // Do nothing
        return true;
    }

    @Override
    public boolean handleMessage(SOAPMessageContext smc) {
        Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (!outboundProperty.booleanValue()) {
            try {
                SOAPBody soapBody = smc.getMessage().getSOAPBody();
                soapBody.removeNamespaceDeclaration("ns0");
                soapBody.addNamespaceDeclaration("s0", "urn:HPD_IncidentInterface_WS");
                SOAPElement oldElement = (SOAPElement) soapBody.getFirstChild();
                cloneToNewNamespace(oldElement, soapBody, "s0");
                soapBody.removeChild(oldElement);
            } catch (SOAPException e) {
                e.printStackTrace();
            }
        }
        return true;
    }

    private void cloneToNewNamespace(Node nodeToRename, SOAPElement parentElement, String prefix) throws SOAPException {
        if (nodeToRename instanceof SOAPElement) {
            SOAPElement elementToRename = (SOAPElement) nodeToRename;
            SOAPElement newElement = parentElement.addChildElement(elementToRename.getElementName().getLocalName(), prefix);
            for (int index = 0; index < elementToRename.getChildNodes().getLength(); index++) {
                Node childNode = elementToRename.getChildNodes().item(index);
                cloneToNewNamespace(childNode, newElement, prefix);
            }
        } else {
            parentElement.addTextNode(nodeToRename.getNodeValue());
        }
    }

    @Override
    public Set<QName> getHeaders() {
        // Do nothing
        return null;
    }
}
于 2012-04-23T17:09:27.757 回答