Skip to main content
Participating Frequently
April 21, 2009
Question

Using WebService served by SAP

  • April 21, 2009
  • 3 replies
  • 6307 views

Greetings,

I have been stuck trying to get CF 8 to talk to SAP serviced Web
Service. Here is code I am using:

<cfscript>
   ws = CreateObject("webservice", "http://xxx.xxxxx.com:8002/sap/bc/
srt/rfc/sap/Z_ZRFC_TEST?sap-client=235&wsdl=1.1
");
   xlatstring = ws.ZZrfcTest(Rfcin = "Hello");
</cfscript>

Here is WSDL file

<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions targetNamespace="urn:sap-
com:document:sap:soap:functions:mc-style" xmlns:wsdl="http://
schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/
XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://
schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="urn:sap-
com:document:sap:soap:functions:mc-style" xmlns:n1="urn:sap-
com:document:sap:rfc:functions">
- <wsdl:documentation>
<sidl:sidl xmlns:sidl="http://www.sap.com/2007/03/sidl" />
</wsdl:documentation>
- <wsdl:types>
- <xsd:schema attributeFormDefault="qualified"
targetNamespace="urn:sap-com:document:sap:rfc:functions">
- <xsd:simpleType name="char10">
- <xsd:restriction base="xsd:string">
<xsd:maxLength value="10" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
- <xsd:schema attributeFormDefault="qualified"
targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style"
xmlns:n0="urn:sap-com:document:sap:rfc:functions">
<xsd:import namespace="urn:sap-com:document:sap:rfc:functions" />
- <xsd:element name="ZZrfcTest">
- <xsd:complexType>
- <xsd:sequence>
<xsd:element name="Rfcin" type="n0:char10" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
- <xsd:element name="ZZrfcTestResponse">
- <xsd:complexType>
- <xsd:sequence>
<xsd:element name="Rfcout" type="n0:char10" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
- <wsdl:message name="ZZrfcTest">
<wsdl:part name="parameters" element="tns:ZZrfcTest" />
</wsdl:message>
- <wsdl:message name="ZZrfcTestResponse">
<wsdl:part name="parameter" element="tns:ZZrfcTestResponse" />
</wsdl:message>
- <wsdl:portType name="Z_ZRFC_TEST">
- <wsdl:operation name="ZZrfcTest">
<wsdl:input message="tns:ZZrfcTest" />
<wsdl:output message="tns:ZZrfcTestResponse" />
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>

here is error message I am getting

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.

Unable to read WSDL from URL:
http://xxxx.xxxxxxx.com:8002/sap/bc/srt/rfc/sap/Z_ZRFC_TEST?sap-client=235&wsdl=1.1

Please advice what to check...

Regards,
Egils

    This topic has been closed for replies.

    3 replies

    ErobsSenAuthor
    Participating Frequently
    April 27, 2009

    I gave up for now after almost two weeks of trying CFINVOKE and CFOBJECT.

    I tried using CFHTTP and it worked. Sure it seems like step backwards but - hey, it works!!!

    I might try using CFINVOKE and CFOBJECT later on but for now I have to deliver something that is functional.

    Thank you for your suggestions. It was great learning experience.

    ErobsSenAuthor
    Participating Frequently
    April 23, 2009

    I am still strugling even with parsed XML attribute however I am not ready investigating WSDL2Java yet...

    Here is how parameters are described in WSDL

    - <xsd:element name="BAPI_PO_GETDETAIL1">
         <xsd:complexType>
    -           <xsd:sequence>
               <xsd:element name="ACCOUNT_ASSIGNMENT" minOccurs="0" type="tns:char1" />
               <xsd:element name="DELIVERY_ADDRESS" minOccurs="0" type="tns:char1" />
               <xsd:element name="HEADER_TEXT" minOccurs="0" type="tns:char1" />
               <xsd:element name="ITEM_TEXT" minOccurs="0" type="tns:char1" />
               <xsd:element name="PURCHASEORDER" type="tns:char10" />
               <xsd:element name="SERVICES" minOccurs="0" type="tns:char1" />
                    <xsd:element name="VERSION" minOccurs="0" type="tns:char1" />
              </xsd:sequence>
         </xsd:complexType>
    </xsd:element>
    Here is how char1 is described
    - <xsd:simpleType name="char1">
        -<xsd:restriction base="xsd:string">
               <xsd:maxLength value="1" />
         </xsd:restriction>
    </xsd:simpleType>
    Here is how Char10 is defined
    <xsd:simpleType name="char10">
        -<xsd:restriction base="xsd:string">
               <xsd:maxLength value="10" />
         </xsd:restriction>
    </xsd:simpleType>
    This is one of the versions of the code I tried
    <cfsavecontent variable="sXML">
        <BAPI_PO_GETDETAIL1>
          <ACCOUNT_ASSIGNMENT/>
          <DELIVERY_ADDRESS/>
          <HEADER_TEXT/>
          <ITEM_TEXT/>
          <PURCHASEORDER>4500000059</PURCHASEORDER>
          <SERVICES/>
          <VERSION/>
        </BAPI_PO_GETDETAIL1>
    /cfsavecontent>
    <cfset xmlObj = XMLParse(sXML)>
    <cfdump var="#sXML#">
    <cfinvoke
          webservice="http://xxxx.xxxxxxxx.com:8006/sap/bc/srt/rfc/sap/Z_PO_GETDETAIL1?sap-client=330&wsdl=1.1"
          method="BAPI_PO_GETDETAIL1"
          refreshWSDL="yes"
          username="web_service"
          password="Seneca09"
         <!--- argumentcollection="#xmlObj#" --->
          returnvariable="aReturn"
    >
          <cfinvokeargument name="BAPI_PO_GETDETAIL1" value="#xmlObj#">
    </cfinvoke>
    Any ideas what I am doing wrong? Any suggestiong or tips?
    Inspiring
    April 23, 2009

    My guess is that it's either the custom data types or the namespace that are what's tripping you up.  Not sure what to do about the data typing aside from the WSDL2Java thing.  You can try adding a namespace to the XML:

    <BAPI_PO_GETDETAIL1 xmlns="http://use/tns/namespace/here">
            <ACCOUNT_ASSIGNMENT />

      ...

    </BAPI_PO_GETDETAIL1>

    ErobsSenAuthor
    Participating Frequently
    April 26, 2009

    Tried that but it did not work. Since I tried to figure out WSDL2JAVA. I got java classes created. I installed Exclipse but that's where it became too complex for me since I have zero to non java experience at this point.

    I run into following article and decided to try it out to run into new issue.

    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19352

    When I tried executing sniffer. I got following errors:

    ERROR: transport error 202: bind failed: address already in use. ERROR: JDWP Transport td_socked failed to initialize...

    I did not find any references in google search regarding error messages listed. Ether way - if sniffer was working it would probably give me some idea what SOAP messages my CF code is sending. I will open new log for sniffer.exe problems I am running into but I just wanted to let anyone who was following this thread to know about sniffer.exe if you did not know about it already.

    Inspiring
    April 22, 2009

    Can you retrieve the WSDL using your browser from the same machine (i.e. your Coldfusion 8 box)?

    If not, that it might be a connection problem between the servers.

    If you can view the WSDL using a browser from the same machine, then try saving the WSDL to a local file and pointing your webservice object instantiation to the local file.  Not a great solution - but it should give you an idea on whether or not there is a networking issue or a file format issue with accessing the WSDL.

    Hope that helps

    - Michael

    ErobsSenAuthor
    Participating Frequently
    April 22, 2009

    I can read WSDL file from CF 8 server and any other computer on my companies network. It does require that I submit usercode and passward which I did when reading WSDL via web-browser. Furthermore SAB Basis admin and I conducted few tests to see if SAP receives any communication request from CF and it does.

    I checked code since initial testing to use CFINVOKE

    <cfinvoke
    webservice="http://xxx.xxxxxxx.com:8006/sap/bc/srt/rfc/sap/Z_PO_GETDETAIL1?sap-client=330&wsdl=1.1"
    method="BAPI_PO_GETDETAIL1"
    refreshWSDL="yes"
    username="xxxxxxx"
    password="xxxxxxx"
    returnvariable="aReturn"
    >

    For testing purposes every call refreshes WSDL and SAP Basis admin could see WSDL request and WSDL returned back by SAP WebService. However we did not see BAPI call initiated from CF

    I have never heard of saving and using WSDL file locally. Could you provide more info how it could be done and how it could help with testing WebService interfaces? Idea of the WebService call CF makes is that SAP will return something back

    Inspiring
    April 22, 2009

    Are you certain that the username/password attributes in the cfinvoke tag are the same as the usercode/password fields that you have to enter to view the WSDL via a browser?  Perhaps the web service call is being stopped at the login screen which is why CF doesn't see a WSDL file at that location.  When you said that you performed some tests with the admin, did that include consuming a simple web service using CF?

    Since the WSDL file just contains a standardized description of the web service methods and data types available to use, it doesn't neccessarily have to reside on the remote web server in order for CF to consume it.  Many WSDL files include a server port element which points back to the remote server - in that case you can download the file as a .wsdl file and point your CF invoke statement to this new file.  For the instances like this where the WSDL xml actually has an element with the URL of your remote server, you can consume the remote web service this way using the local WSDL.

    <cfinvoke

    webservice="http://mycf8server/path/to/file/myfile.wsdl

    ...

    >

    That being said, its not a great idea to do it this way.  For one, you'd have to set up a system to automatically download and update the local WSDL file on your CF server  otherwise it would quickly become outdated and stop working.  For testing purposes, though, saving the wsdl file locally and calling it from coldfusion should give you an idea whether the issue is the WSDL/XML content or an issue with the data transmission between the CF server and the SAP server.