本文主要是介绍第三十二章 使用带附件的 SOAP - 示例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 第三十二章 使用带附件的 SOAP - 示例
- 示例
- `Web Service`
- Web Client
第三十二章 使用带附件的 SOAP - 示例
示例
本节提供了相互发送附件的 Web
服务和 Web
客户端示例。
Web Service
Web
服务提供了两种方法:
UploadAscii()
接收ASCII
附件并保存。DownloadBinary()
向请求者发送二进制附件。
该类定义如下:
Class GSOAP.FileTransferWS Extends %SOAP.WebService
{/// Name of the web service.
Parameter SERVICENAME = "FileTransfer";/// SOAP namespace for the web service
Parameter NAMESPACE = "https://www.filetransfer.org";/// Namespaces of referenced classes will be used in the WSDL.
Parameter USECLASSNAMESPACES = 1;/// Receive an attachment and save it
Method UploadAscii(filename As %String = "sample.txt") As %Status [WebMethod]
{//assume 1 attachment; ignore any othersSet attach=..Attachments.GetAt(1)Set file=##class(%FileCharacterStream).%New()Set file.Filename="c:\from-client"_$H_filename//copy attachment into fileSet status=file.CopyFrom(attach.Body)If $$$ISERR(status) {do $System.Status.DisplayError(status)}Set status= file.%Save() Quit status
}/// Create an attachment and send it in response to the web client call
Method DownloadBinary(filename As %String = "sample.pdf") As %Status [WebMethod]
{//use a file-type stream to read file contentsSet file=##class(%Library.FileBinaryStream).%New()Set file.Filename="c:\"_filename//create MIMEpart and add file to itSet mimepart=##class(%Net.MIMEPart).%New() Set mimepart.Body=file//set header appropriately for binary fileDo mimepart.SetHeader("Content-Type","application/octet-stream")Do mimepart.SetHeader("Content-Transfer-Encoding","binary")//attachSet status=..ResponseAttachments.Insert(mimepart) Quit status
}}
Web Client
Web
客户端应用程序提供了两种方法:
UploadAscii()
将ASCII
文件发送到Web
服务。DownloadBinary()
调用Web
服务并接收响应中的二进制文件。
生成的 Web
客户端类 (GSOAPClient.FileTransfer.FileTransferSoap
) 包含方法 UploadAscii()
和 DownloadBinary()
,它们调用了前面 Web
服务的相应方法。此类未显示。
Web
客户端应用程序还包括以下类,该类使用此生成的 Web
客户端类:
Include %systemIncludeClass GSOAPClient.FileTransfer.UseClient
{ClassMethod DownloadBinary(filename As %String = "sample.pdf") As %Status
{Set client=##class(GSOAPClient.FileTransfer.FileTransferSoap).%New()//call web methodSet 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 uniqueSet file.Filename="c:\from-service"_$H_filenameSet 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 contentsSet file=##class(%Library.FileCharacterStream).%New()Set file.Filename="c:\"_filename//create MIME part, add file as Body, and set the headerSet mimepart=##class(%Net.MIMEPart).%New() Set mimepart.Body=fileDo mimepart.SetHeader("Content-Transfer-Encoding","7bit")//attach to client and call web methodDo client.Attachments.Insert(mimepart) Set status=client.UploadAscii(filename)Quit status
}}
这篇关于第三十二章 使用带附件的 SOAP - 示例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!