Kbase P118318: How to use WebSpeed to publish Web Services?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  29/09/2009 |
|
Status: Verified
GOAL:
How to use WebSpeed to publish Web Services?
GOAL:
Is there a way to publish Web Service from WebSpeed without using the Web Services Adaptor?
FIX:
The following is a sample WebSpeed application that shows how to publish a Web Service in WebSpeed. Please note this is not an approach Progress supports, use it at your own risk. Progress recommends using the Web Services Adapter instead.
&ANALYZE-SUSPEND _VERSION-NUMBER AB_v10r12
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
/*------------------------------------------------------------------------
File: webspeed_web_service.w
Publish a SOAP web service using a WebSpeed routine.
This does NOT require that you install the Progress Web Services Adapter.
This also does NOT require that you install Apache Tomcat.
Use this routine like any other WebSpeed routine.
The URL for the web service will be in the form of:
http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w
And the WSDL document for the web service will be in the form of:
http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w?WSDL
You can test the links in a web browser and they will display XML documents.
Please note that this is only a sample - you will need to
modify the output statements for your particular web service.
------------------------------------------------------------------------*/
/* This .W file was created with the Progress AppBuilder. */
/*----------------------------------------------------------------------*/
CREATE WIDGET-POOL.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
/* ******************** Preprocessor Definitions ******************** */
&Scoped-define PROCEDURE-TYPE Procedure
&Scoped-define DB-AWARE no
/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME
/* *********************** Procedure Settings ************************ */
&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
Type: Procedure
Allow:
Frames: 0
Add Fields to: Neither
Other Settings: CODE-ONLY
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS
/* ************************* Create Window ************************** */
&ANALYZE-SUSPEND _CREATE-WINDOW
/* DESIGN Window definition (used by the UIB)
CREATE WINDOW Procedure ASSIGN
HEIGHT = 14.14
WIDTH = 60.6.
/* END WINDOW DEFINITION */
*/
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
/* ************************* Included-Libraries *********************** */
{src/web2/wrap-cgi.i}
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
/* ************************ Main Code Block *********************** */
/* read the incoming SOAP message */
IF WEB-CONTEXT:IS-XML THEN DO: /* if input is in XML format */
/* save incoming XML to a text file */
DEF VAR hDocOut AS HANDLE.
DEFINE STREAM xmlstream.
OUTPUT STREAM xmlstream TO c:\temp.xml.
hDocOut:SAVE("stream","xmlstream").
OUTPUT STREAM xmlstream CLOSE.
/* load into memory the saved text file which contains the XML */
/* load it into temp-table records, variables, or whatever you like */
/* here we use a temp-table called 'zelement' */
DEF VAR hDocIn AS HANDLE.
DEF VAR hRoot AS HANDLE.
CREATE X-DOCUMENT hDocIn.
CREATE X-NODEREF hRoot.
hDocIn:LOAD("file","c:\temp.xml",TRUE).
hDocIn:GET-DOCUMENT-ELE.MENT(hRoot).
DEF TEMP-TABLE zelement
FIELD zlabel AS CHAR
FIELD zvalue AS CHAR.
RUN GetChildren(hRoot, 1).
DELETE OBJECT hDocIn.
DELETE OBJECT hRoot.
END.
/* process the information */
DEF VAR zresult AS INTEGER.
FIND FIRST zelement WHERE zelement.zlabel = "firstnumber" NO-ERROR.
IF AVAILABLE zelement THEN zresult = int(zelement.zvalue) * 2.
/* Process the latest Web event. */
RUN process-web-request.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* ********************** Internal Procedures *********************** */
&IF DEFINED(EXCLUDE-GetChildren) = 0 &THEN
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE GetChildren Procedure
PROCEDURE GetChildren :
/* parse the XML document and save the elements in a temp-table */
DEFINE INPUT PARAMETER hParent AS HANDLE.
DEFINE INPUT PARAMETER level AS INTEGER.
DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE good AS LOG.
DEFINE VARIABLE templabel AS CHAR.
DEFINE VARIABLE tempvalue AS CHAR.
DEFINE VARIABLE hNoderef AS HANDLE.
CREATE X-NODEREF hNoderef.
REPEAT i = 1 TO hParent:NUM-CHILDREN:
good = hParent:GET-CHILD(hNoderef,i).
IF NOT good THEN LEAVE.
IF hNoderef:SUBTYPE = "element" THEN templabel = hNoderef:NAME.
IF hNoderef:SUBTYPE = "text" THEN tempvalue = hNoderef:NODE-VALUE.
IF hNoderef:SUBTYPE = "text" THEN DO:
CREATE zelement.
ASSIGN zelement.zlabel = templabel
zelement.zvalue = tempvalue.
END.
RUN GetChildren(hNoderef, (level + 1)).
END.
DELETE OBJECT hNoderef.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ENDIF
&IF DEFINED(EXCLUDE-outputHeader) = 0 &THEN
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE outputHeader Procedure
PROCEDURE outputHeader :
/* make sure type is XML (not HTML) - this will return an XML page */
/*output-content-type ("text/html":U).*/
output-content-type ("text/xml":U).
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ENDIF
&IF DEFINED(EXCLUDE-process-web-request) = 0 &THEN
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE process-web-request Procedure
PROCEDURE process-web-request :
RUN outputHeader.
DEF VAR xquerystring AS CHAR.
xquerystring = get-cgi("QUERY_STRING").
/* WSDL document */
IF xquerystring = "WSDL" THEN DO:
/* here is the WSDL document - please note this is only a sample */
/* you will need to modify this for your particular web service */
{&OUT} '<?xml version="1.0" encoding="UTF-8"?>' SKIP.
{&OUT} '<definitions name="YourService" '
'targetNameSpace="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w?WSDL" '
'xmlns:tns="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w?WSDL" '
'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
'xmlns:wsx="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w/readxml.xsd" '
'xmlns="http://schemas.xmlsoap.org/wsdl/">' SKIP.
{&OUT} '<types>' SKIP.
{&OUT} '<xsd:schema targetNamespace="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w/readxml.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' SKIP.
{&OUT} '<xsd:complexType name="YourService">' SKIP.
{&OUT} '<xsd:sequence>' SKIP.
{&OUT} '<xsd:e.lement maxOccurs="1" minOccurs="1" name="firstnumber" nillable="true" type="xsd:string"/>' SKIP.
{&OUT} '<xsd:element maxOccurs="1" minOccurs="1" name="result" nillable="true" type="xsd:string"/>' SKIP.
{&OUT} '</xsd:sequence>' SKIP.
{&OUT} '</xsd:complexType>' SKIP.
{&OUT} '</xsd:schema>' SKIP.
{&OUT} '</types>' SKIP.
{&OUT} '<message name="AddInput">' SKIP.
{&OUT} '<part name="YourServiceData" type="wsx:YourService"/>' SKIP.
{&OUT} '<part name="port" type="xsd:string"/>' SKIP.
{&OUT} '<part name="transportName" type="xsd:string"/>' SKIP.
{&OUT} '</message>' SKIP.
{&OUT} '<message name="AddResponse">' SKIP.
{&OUT} '<part name="YourServiceData" type="wsx:YourService"/>' SKIP.
{&OUT} '</message>' SKIP.
{&OUT} '<portType name="YourServicePortType">' SKIP.
{&OUT} '<operation name="Add">' SKIP.
{&OUT} '<input message="tns:AddInput"/>' SKIP.
{&OUT} '<output message="tns:AddResponse"/>' SKIP.
{&OUT} '</operation>' SKIP.
{&OUT} '</portType>' SKIP.
{&OUT} '<binding name="YourServiceBinding" type="tns:YourServicePortType">' SKIP.
{&OUT} '<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>' SKIP.
{&OUT} '<operation name="Add">' SKIP.
{&OUT} '<soap:operation soapAction="Add"/>' SKIP.
{&OUT} '<input>' SKIP.
{&OUT} '<soap:body use="encoded" namespace="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>' SKIP.
{&OUT} '</input>' SKIP.
{&OUT} '<output>' SKIP.
{&OUT} '<soap:body use="encoded" namespace="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>' SKIP.
{&OUT} '</output>' SKIP.
{&OUT} '</operation>' SKIP.
{&OUT} '</binding>' SKIP.
{&OUT} '<service name="YourServiceService" >' SKIP.
{&OUT} '<documentation>' SKIP.
{&OUT} 'Returns a sum of two numbers' SKIP.
{&OUT} '</documentation>' SKIP.
{&OUT} '<port name="YourServicePort" binding="tns:YourServiceBinding">' SKIP.
{&OUT} '<soap:address location="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w"/>' SKIP.
{&OUT} '</port>' SKIP.
{&OUT} '</service>' SKIP.
{&OUT} '</definitions>' SKIP.
END.
/* SOAP message */
ELSE DO:
/* here is the SOAP message returned - please note this is only a sample */
/* you will need to modify this for your particular web service */
{&OUT} '<?xml version="1.0" encoding="UTF-8"?>' SKIP.
{&OUT} '<env:Envelope xmlns:env=" http://schemas.xmlsoap.org/soap/envelope/">' SKIP.
{&OUT} '<env:Body>' SKIP.
{&OUT} '<m:YourService xmlns:m="http://www.yourserver.com/scripts/cgiip.exe/WService=wsbroker1/webservice.w">' SKIP.
{&OUT} '<m:result>' zresult '</m:result>' SKIP.
{&OUT} '</m:YourService>' SKIP.
{&OUT} '</env:Body>' SKIP.
{&OUT} '</env:Envelope>' SKIP.
END.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ENDIF
.