Web Service Basics: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
mNo edit summary
Adding more...
Line 1: Line 1:
==Mechanisms==
==Mechanisms==


====Creating a WebApp Project====
===Creating a WebApp Project===
In the [[Visual DataFlex Studio]], select <span style="color:blue; font-weight:bold">File => New => Project => Web Project</span> and follow the wizard's instructions.
In the [[Visual DataFlex Studio]], select <span style="color:blue; font-weight:bold">File => New => Project => Web Project</span> and follow the wizard's instructions.
----


====Creating a Web Service Object====
===Creating a Web Service Object===
In the [[Visual DataFlex Studio]], select <span style="color:blue; font-weight:bold">File => New => Web Object => Web Service Object</span> and follow the wizard's instructions.
In the [[Visual DataFlex Studio]], select <span style="color:blue; font-weight:bold">File => New => Web Object => Web Service Object</span> and follow the wizard's instructions.


The '''psDocumentation''' property will be automatically set to some default text, but you should replace this with a description of your own service, as this will appear in the [[WSDL]] <nowiki><documentation></nowiki> element describing the service.  There are several other properties which it now a good idea to set:
The '''psDocumentation''' property will be automatically set to some default text, but you should replace this with a description of your own service, as this will appear in the [[WSDL]] <nowiki><documentation></nowiki> element describing the service.  There are several other properties which it now a good idea to set:


* '''psServiceURI''' - this should be set to a unique URI; a good choice is something like "http://''yourDomainName''/''projectName''/''serviceName'' - there is <u>no requirement</u> that it actually exist as a valid URL
* '''psServiceURI''' - this should be set to a unique URI; a good choice is something like "http://''yourDomainName''/''projectName''/''serviceName'' - there is <u>no requirement</u> that it actually exist as a valid internet URL
* '''psServiceName''' - this will be used to name the exposed web service object (.wso) and hence will be part of the "''endpoint''" URL of your service, so chose it with care
* '''psServiceName''' - this will be used to name the exposed web service object (.wso) and hence will be part of the "''endpoint''" URL of your service, so chose it with care
* '''psServiceTitle''' - this will appear as the "display" name of the service in the human-readable HTML interface to the service
* '''psServiceTitle''' - this will appear as the "display" name of the service in the human-readable HTML interface to the service
----


====Publishing a Method====
====Defining XML Documents====
In the [[Code Explorer]] pane in the [[Visual DataFlex Studio]], right-click on the method and select "'''Published'''" from the context menuThis will cause (a) the "Published" item to subsequently appear "checked", (b) a globe to appear next to the method's icon in Code Explorer and (c) the lines:
Assuming that you are using [[Visual DataFlex]]'s default [http://www.ibm.com/developerworks/webservices/library/ws-docstyle.html Document Style] of web service, you will generally need to define the [[XML]] documents that are passed to and from your service's operationsIf these are anything other than simple data types (String, Integer, etc.) then you will need to define them as [[Struct]]s.  An example of such a thing would be:


  { Published = True  }
  Struct OrderDetail
  { Description = ""  }
    Integer LineNo
    String  ItemCode
    Number  Price
    Integer Quantity
End_Struct  // OrderDetail
Struct PurchaseOrder
    String  OrderNum
    String  CustomerID
    Date    OrderDate
    Number  OrderTotal
    OrderDetail[] Details
    String  PayMethod
End_Struct  // PurchaseOrder
Struct OrderResponse
    Boolean Accepted
    String  RejectReason
    Integer OrderNum
    String  Reference
    Date    DeliveryDate
End_Struct  // OrderResponse
----
 
====Defining Web Service Operations====
These documents are then used in web service ''methods'' (Functions or Procedures) like this:
 
Function GoodsOrder PurchaseOrder Ord Returns OrderResponse
  OrderResponse Resp
  Get ProcessOrder Ord to Resp.Accepted
  If Not Resp.Accepted Get psOrderError to Resp.RejectReason
  Else Begin
      Get piOrdNum  to Resp.OrderNum
      Get psRef      to Resp.Reference
      Get pdDelivery to Resp.DeliveryDate
  End
  Function_Return Resp
End_Function  // GoodsOrder
 
(Here it is assumed that there is also defined a Function ''ProcessOrder'', which does all of the hard work, taking the PurchaseOrder data and returning a boolean result - and setting various properties as it does so.)
----
 
====Publishing an Operation====
In the [[Code Explorer]] pane of the [[Visual DataFlex Studio]], right-click on the method (Function or Procedure) and select "'''Published'''" from the context menu.  This will cause (a) the "Published" context-menu item to subsequently appear "checked", (b) a globe to appear next to the method's icon in Code Explorer and (c) the two lines:
 
<span style="color:blue;">{ Published = True  }
  { Description = ""  }</span>
<span style="color:gray;">Function GoodsOrder PurchaseOrder Ord Returns OrderResponse</span>


to appear above the method declaration line.  The ''Description'' should then be filled-in with something meaningful, as this will form the <nowiki><documentation></nowiki> element in the [[WSDL]] describing the method (''operation'' in web service terminology).  If you later chose to "unpublish" the method (uncheck "Published" on the context menu), the "True" will change to "False", however you could also just delete the two lines in braces, at the cost of losing anything you had written into the "Description" there.
to appear above the method declaration line.  The ''Description'' should then be filled-in with something meaningful, as this will form the <nowiki><documentation></nowiki> element in the [[WSDL]] describing the method (''operation'' in web service terminology).  If you later chose to "unpublish" the method (uncheck "Published" on the context menu), the "True" will change to "False", however you could also just delete the two lines in braces, at the cost of losing anything you had written into the "Description" there.
----


====Creating a Web Service Client====
===Creating a Web Service Client===
In the [[Visual DataFlex Studio]], select <span style="color:blue; font-weight:bold">File => New => Class => Client Web Service Class</span>.
In the [[Visual DataFlex Studio]], select <span style="color:blue; font-weight:bold">File => New => Class => Client Web Service Class</span>.

Revision as of 19:01, 21 November 2007

Mechanisms

Creating a WebApp Project

In the Visual DataFlex Studio, select File => New => Project => Web Project and follow the wizard's instructions.


Creating a Web Service Object

In the Visual DataFlex Studio, select File => New => Web Object => Web Service Object and follow the wizard's instructions.

The psDocumentation property will be automatically set to some default text, but you should replace this with a description of your own service, as this will appear in the WSDL <documentation> element describing the service. There are several other properties which it now a good idea to set:

  • psServiceURI - this should be set to a unique URI; a good choice is something like "http://yourDomainName/projectName/serviceName - there is no requirement that it actually exist as a valid internet URL
  • psServiceName - this will be used to name the exposed web service object (.wso) and hence will be part of the "endpoint" URL of your service, so chose it with care
  • psServiceTitle - this will appear as the "display" name of the service in the human-readable HTML interface to the service

Defining XML Documents

Assuming that you are using Visual DataFlex's default Document Style of web service, you will generally need to define the XML documents that are passed to and from your service's operations. If these are anything other than simple data types (String, Integer, etc.) then you will need to define them as Structs. An example of such a thing would be:

Struct OrderDetail
   Integer LineNo
   String  ItemCode
   Number  Price
   Integer Quantity
End_Struct  // OrderDetail

Struct PurchaseOrder
   String  OrderNum
   String  CustomerID
   Date    OrderDate
   Number  OrderTotal
   OrderDetail[] Details
   String  PayMethod
End_Struct  // PurchaseOrder

Struct OrderResponse
   Boolean Accepted
   String  RejectReason
   Integer OrderNum
   String  Reference
   Date    DeliveryDate
End_Struct  // OrderResponse

Defining Web Service Operations

These documents are then used in web service methods (Functions or Procedures) like this:

Function GoodsOrder PurchaseOrder Ord Returns OrderResponse
  OrderResponse Resp

  Get ProcessOrder Ord to Resp.Accepted

  If Not Resp.Accepted Get psOrderError to Resp.RejectReason
  Else Begin
     Get piOrdNum   to Resp.OrderNum
     Get psRef      to Resp.Reference
     Get pdDelivery to Resp.DeliveryDate
  End

  Function_Return Resp
End_Function  // GoodsOrder

(Here it is assumed that there is also defined a Function ProcessOrder, which does all of the hard work, taking the PurchaseOrder data and returning a boolean result - and setting various properties as it does so.)


Publishing an Operation

In the Code Explorer pane of the Visual DataFlex Studio, right-click on the method (Function or Procedure) and select "Published" from the context menu. This will cause (a) the "Published" context-menu item to subsequently appear "checked", (b) a globe to appear next to the method's icon in Code Explorer and (c) the two lines:

{ Published = True  }
{ Description = ""  }
Function GoodsOrder PurchaseOrder Ord Returns OrderResponse

to appear above the method declaration line. The Description should then be filled-in with something meaningful, as this will form the <documentation> element in the WSDL describing the method (operation in web service terminology). If you later chose to "unpublish" the method (uncheck "Published" on the context menu), the "True" will change to "False", however you could also just delete the two lines in braces, at the cost of losing anything you had written into the "Description" there.


Creating a Web Service Client

In the Visual DataFlex Studio, select File => New => Class => Client Web Service Class.