0
我的要求是爲不包含soap的請求添加soap包裝器,如果請求確實有soap包裝器,則不執行任何操作。添加肥皂信封或使用XSLT 1.0保持相同
案例1:添加簡單XML請求的soap包裝器。
案例2:發送有效負載,以防萬一它已經是SOAP。
代碼:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This stylesheet adds one or removes a SOAP envelope if one is found -->
<xsl:stylesheet version="1.0" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="contains(.,'Envelope') = 'true' ">
<xsl:copy-of select="/"/>
</xsl:when>
<xsl:otherwise>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header/>
<soap:Body>
<xsl:copy-of select="/"/>
</soap:Body>
</soap:Envelope>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
樣品要求工作之一:
<ProductMovementReport xmlns="urn:cidx:names:specification:ces:schema:all:5:0" Version="5.0">
<Header>
<ThisDocumentIdentifier>
<DocumentIdentifier>1044911</DocumentIdentifier>
</ThisDocumentIdentifier>
</Header>
<ProductMovementReportBody>
<ProductMovementReportDetails>
<ReportingEntity>
<PartnerInformation>
<PartnerName>CHS</PartnerName>
<PartnerIdentifier Agency="GLN">123456</PartnerIdentifier>
</PartnerInformation>
</ReportingEntity>
</ProductMovementReportDetails>
</ProductMovementReportBody>
</ProductMovementReport>
此轉換成SOAP消息成功
Sample_request_WithSOAPwrapper
請求:
<soap:Envelope xmlns:tns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header/>
<soap:Body>
<ProductMovementReport xmlns="urn:cidx:names:specification:ces:schema:all:5:0" Version="5.0">
<Header>
<ThisDocumentIdentifier>
<DocumentIdentifier>1044911</DocumentIdentifier>
</ThisDocumentIdentifier>
</Header>
<ProductMovementReportBody>
<ProductMovementReportDetails>
<ReportingEntity>
<PartnerInformation>
<PartnerName>CHS</PartnerName>
<PartnerIdentifier Agency="GLN">123456</PartnerIdentifier>
</PartnerInformation>
</ReportingEntity>
</ProductMovementReportDetails>
</ProductMovementReportBody>
</ProductMovementReport>
</soap:Body>
</soap:Envelope>
給出輸出:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:tns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header/>
<soap:Body>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header/>
<soap:Body>
<ProductMovementReport xmlns="urn:cidx:names:specification:ces:schema:all:5:0" Version="5.0">
<Header>
<ThisDocumentIdentifier>
<DocumentIdentifier>1044911</DocumentIdentifier>
</ThisDocumentIdentifier>
</Header>
<ProductMovementReportBody>
<ProductMovementReportDetails>
<ReportingEntity>
<PartnerInformation>
<PartnerName>CHS</PartnerName>
<PartnerIdentifier Agency="GLN">123456</PartnerIdentifier>
</PartnerInformation>
</ReportingEntity>
</ProductMovementReportDetails>
</ProductMovementReportBody>
</ProductMovementReport>
</soap:Body>
</soap:Envelope>
</soap:Body>
</soap:Envelope>
更新:我沒加什麼,我面臨的問題。
問題是添加了額外的肥皂包裝。
<soap:Envelope xmlns:tns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header/>
<soap:Body>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header/>
<soap:Body>
</soap:Body>
</soap:Envelope>
</soap:Body>
</soap:Envelope>
任何人都可以請告知我在哪裏做錯了?
我的猜測是我做錯了測試條件。
感謝邁克爾指着我的更好的方法。 –