This section provides an example web service and web client that send attachments to each other.
Web Client
The web client application provides two methods:
The generated web client class (GSOAPClient.FileTransfer.FileTransferSoap) includes the methods UploadAscii() and DownloadBinary(), which invoke the corresponding methods of the preceding web service. This class is not shown.
The web client application also includes the following class, which uses this generated web client class:
Include %systemInclude
Class GSOAPClient.FileTransfer.UseClient
{
ClassMethod DownloadBinary(filename As %String = "sample.pdf") As %Status
{
Set client=##class(GSOAPClient.FileTransfer.FileTransferSoap).%New()
//call web method
Set ans=client.DownloadBinary(filename)
//get the attachment (assume only 1)
Set attach=client.ResponseAttachments.GetAt(1)
//create a file and copy stream contents into it
Set file=##class(%FileBinaryStream).%New()
//include $H in the filename to make filename unique
Set file.Filename="c:\from-service"_$H_filename
Set status=file.CopyFrom(attach.Body)
If $$$ISERR(status) {do $System.Status.DisplayError(status)}
Set status= file.%Save()
Quit status
}
ClassMethod UploadAscii(filename As %String = "sample.txt") As %Status
{
Set client=##class(GSOAPClient.FileTransfer.FileTransferSoap).%New()
//use a file-type stream to read file contents
Set file=##class(%Library.FileCharacterStream).%New()
Set file.Filename="c:\"_filename
//create MIME part, add file as Body, and set the header
Set mimepart=##class(%Net.MIMEPart).%New()
Set mimepart.Body=file
Do mimepart.SetHeader("Content-Transfer-Encoding","7bit")
//attach to client and call web method
Do client.Attachments.Insert(mimepart)
Set status=client.UploadAscii(filename)
Quit status
}
}