Consuming Webservices with tag in WSDL using XSLT


SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

Consuming Webservices with <ANY> tag in WSDL using XSLT

Have you seen the blog Consuming Webservices with <ANY> tag in WSDL using ABAP  where posted the ABAP solution of empty structures in .Net WEB services? This blog shows another approach – XSLT mapping program.

The problem is in that fact that WSDL file generated with .Net WEB service (MS Project server, MS SharePoint server, etc.) contains link

<s:any namespace=" ...  " xmlns:s="http://www.w3.org/2001/XMLSchema" />

 

in element

<s:sequence  xmlns:s="http://www.w3.org/2001/XMLSchema"> ... </s:sequence>

 

of message type definition. Here target is in “namespace” attribute. Using this WSDL in SAP XI/PI, you will get a message without fields in message mapping. At runtime there will be only one element with whole message into it as its value.

You can modify WSDL copying this structure in “sequence” element of cause but to my mind it is not right way.

Using ABAP is not suitable in some cases, especially when you haven’t got OSS key.

I have solved this problem using XSLT.  

So, I got a response from MS Project’s WEB service like this:

 <?xml version="1.0" encoding="UTF-8"?>
 <ReadProjectListResponse xmlns="http://schemas.microsoft.com/office/project/server/webservices/Project/">
 <ReadProjectListResult>
 <xs:schema ... > ... </xs:schema>
 <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
 <ProjectDataSet xmlns="http://schemas.microsoft.com/office/project/server/webservices/ProjectDataSet/">
     <Project diffgr:id="Project1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
        <PROJ_UID>674457db-7ff1-4e24-81b3-b41d5594f27f</PROJ_UID>
        <PROJ_NAME>Project1</PROJ_NAME>
     </Project>
     <Project diffgr:id="Project2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
        <PROJ_UID>3dc33ef5-c796-4b01-8707-3b1f225f741c</PROJ_UID>
        <PROJ_NAME>Project2</PROJ_NAME>
     </Project>
</ProjectDataSet>
</diffgr:diffgram>
</ReadProjectListResult>
</ReadProjectListResponse>

          

In this message I want to get a list of  Projects UIDs (<PROJ_UID>).

First step was “cut” redundant namespaces using XMLAnonymizerBean module

image

Next, I wrote script like this:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="ProjectDataSet">
  <MT_Project_List>
    <xsl:apply-templates />
  </MT_Project_List>
</xsl:template>
<xsl:template match="Project">
   <row>
      <xsl:apply-templates select="PROJ_UID" />
   </row>
</xsl:template>

<xsl:template match="PROJ_UID">
   <projectUID>
      <xsl:apply-templates />
   </projectUID>
</xsl:template>
</xsl:stylesheet>

         

In this script templates

<xsl:template match="XXXX">
  <YYYY>
    <xsl:apply-templates />
  </YYYY>
</xsl:template>

 

search <XXXX> elements in input XML, call next template and put its result in <YYYY> element of output file. If next template is not exists, it returns value of current element.

So, my response from MS Project transforms to:

 <?xml version="1.0" encoding="UTF-8"?>
<MT_Project_List>
<row>
   <projectUID>674457db-7ff1-4e24-81b3-b41d5594f27f</projectUID>
</row>
<row>
   <projectUID>3dc33ef5-c796-4b01-8707-3b1f225f741c</projectUID>
</row>
</MT_Project_List>

 

It works!

And the last step – is to archive an XSLT file, import it as Imported Archive and choose it in Interface Mapping as mapping program (type=XSL).

SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

P.S.

If you need to get 2 or more fields, your XSLT should be a changed. For example, XSLT for Projects IDs and Names:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="ProjectDataSet">
  <MT_Project_List>
    <xsl:apply-templates />
  </MT_Project_List>
</xsl:template>

<xsl:template match="Project">
   <row>
      <xsl:apply-templates select="PROJ_UID" />
      <xsl:apply-templates select="PROJ_NAME" />
   </row>
</xsl:template>

<xsl:template match="PROJ_UID">
   <projectUID>
      <xsl:apply-templates />
   </projectUID>
</xsl:template>

<xsl:template match="PROJ_NAME">
   <projectNAME>
      <xsl:apply-templates />
   </projectNAME>
</xsl:template>

</xsl:stylesheet>

 

Output:

<?xml version="1.0" encoding="UTF-8"?>
<MT_Project_List>
<row>
  <projectUID>674457db-7ff1-4e24-81b3-b41d5594f27f</projectUID>
  <projectNAME>Project1</projectNAME>
</row>
<row>
  <projectUID>3dc33ef5-c796-4b01-8707-3b1f225f741c</projectUID>
  <projectNAME>Project2</projectNAME>
</row>
</MT_Project_List>

SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter
en.pdf24.org    Send article as PDF   
This entry was posted in sap pi 7.1 tutorials. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *