Microsoft SOAP Toolkit
This section shows you how to write a SOAP client using the Microsoft SOAP Toolkit. The MS SOAP Toolkit is a set of DLLs which can be exploited from an any language within the COM (Component Object Model) family (as long, of course, as the executable is running on a Win32 system). The language we will be looking at in this tutorial is Visual Basic.
이 섹션에서 Microsoft SOAP Toolkit을 사용하여 어떻게 SOAP client를 작성하는지 여러분에게 보여줄 것이다. MS SOAP Toolkit은 COM Family안에서그 어떠한 언어도도 개발될 수 있는 DLLs 세트이다. 개발할 언어로 우리는 비주얼베이직을 사용한 튜토리얼을 보여줄 것이다.
Introduction
We will be writing a very simple VB SOAP client which will exploit the Quotation Service as described and developed in the Section 4 of Server-Side SOAP.
우리는 Server-Side SOAP에서 개발하고 서술한 Quotation을 사용하는 아주 간단한 VB SOAP을 작성할 것이다.
The SOAP-related VB code in the client we will develop here can easily be incorporated into a VB Macro to SOAP-enable an Excel Spreadsheet. We will take a look at how to do that as well. While it is true that you can exploit the MS SOAP Toolkit DLLs from many languages other than VB, it is not our intention to cover them all.
클라이언트의 VB와 관련된 SOAP 코드는 하나의 엑셀 스프레드시트 SOAP-enable에 VB Macro를 병합하여 손쉽게 개발할 수 있다. 우리는 아주 자세시 어떻게 개발하는지 볼 수 있다. 여러분이 많은 다른 VB 언어로 MS SOAP DLLs를 사용할수 있는 것은 사실이지만, 여기에서 모든것을 다루지는 않는다.
As is the case when writing clients to any SOAP service, ensure in advance that you are familiar with the service and its method signatures.
그 어떤 SOAP 서비스에 대해 작성하는 경우에는 더 향상되게 하기 위해 여러분은 서비스와 메소드 서명에 대해 친숙해야 한다.
We will build a single VB client which will exploit all three service methods.
우리는 세가지 서비스 메소드 모두를 사용하는 VB 클라이언트를 개발할 것이다.
Note that there are actually two APIs in the Microsoft SOAP Toolkit. They are the so-called High Level API (which involves the use of wsdl and wsml files for service description) and the Low Level API (which does not require the preparation of such files and is as a result more verbose in terms of code but at the same time more powerful). The API used in this tutorial is the Low Level API.
Microsoft SOAP Toolkit에서 실제로 두 개의 API가 있다. 그들은 High Level API 과 Low Level API가 있다. 이 튜토리얼에서는 Low Level API 를 사용했다.
Check your Visual Basic Version
You will need Visual Basic 6.0 Service Pack 4 or later (this is the version delivered with Visual Studio 6.0 Service Pack 4). To check your version open up Visual Basic and choose Help / About Microsoft Visual Basic.
여러분은 Visual Basic 6.0 Service Pack 4 혹은 그 이상의 버전을 필요로 한다. 여러분의 VB를 실행하고 Help / About Microsoft Visual Basic 를 선택하여 버전을 확인하길 바란다.
If you have Visual Basic 6.0 but are at an earlier Service Pack level you can download SP4 from Microsoft Product Support Services.
만약 VB 6.0를 사용하지만 이전 버전의 서비스 펙이면 여러분은 SP4(혹은 이상 버전)을 다운로드 받아야 한다.
If you have a version prior to 6.0, or do not have Visual Basic at all, unfortunately, unlike the rest of the packages used on this site, you cannot download it for free. You can however still go through the source code here and run the VB demo found in the Demo Section.
여러분이 만약 6.0 이전의 버전 혹은 VB를 가지고 있지 않다면, 불행하게도 이 사이트의 팩키지를 사용할 수 없다. 여러분은 vb 6.0을 공짜로 다운로드 할 수 없다. 그러나 여전히 여기 소스 코드를 사용하고 그리고 Demo 섹션에서 VB 데모를 실행할 수 있다.
Installing the MS SOAP Toolkit
Before you install the actual toolkit, you will need to ensure that you have the following on your system:
여러분은 실제 Toolkit을 설치하기 전에, 여러분의 시스템에서 다음을 따르기 위한 확실한 방법이 필요할 것이다.
* Internet Explorer 5.5 or later (this will ensure you have the correct version of the HTTP connector libraries) - if you have a prior version then 5.5 can be downloaded free of charge from Microsoft's IE download page.
* Microsoft Installer (MSI) functionality (which allows you to run the SOAP toolkit installer) - this comes standard with Windows 2000 and Windows Me so users of these systems will not need to do anything. If you are using Windows NT then download MSI 1.1+ for NT. If you are using Win95 or Win98 then download MSI 1.1+ for Win9x.
- 인터넷 익스플로러 5.5 혹은 그 이상 버전
- Microsoft Installer (MSI) functionality
Now for the toolkit itself. We will be using Microsoft SOAP Toolkit 2.0 SP2. To install this on your machine go to the MS SOAP Toolkit download area and choose the download entitled "Soap Toolkit 2.0 SP2", read and accept the license agreement (if you are happy with the terms) and save the file to your machine. You should now have a file called soaptoolkit20.exe. This is a self-extracting executable that exploits MSI functionality. Run it and follow the onscreen instructions to install the toolkit. When asked, opt for the COMPLETE install.
우리는 Microsoft SOAP Toolkit 2.0 SP2를 사용할 것이다. 여러분의 컴퓨터에 이것을 설치하는 것은 MS SOAP Toolkit download 페이지로 가서 Soap Toolkit 2.0 SP2 선택하고, 라이센스에 동의해서 여러분의 시스템에 저장할 수 있다. 지금 여러분은 soaptoolkit20.exe 를 실행해야 한다. 이 파일은 MSI functionality를 사용하여 자동적으로 설치될 것이다.
Understanding the API
Following is the bare-essentials VB code required to exploit the API. It is paraphrased from the VB source downloadable further down this page. Note that we have chopped out just the SOAP-related code, so what you see when you open up the downloaded source will be basically the same but slightly rearranged and more verbose to handle the GUI aspects of the client (which we will not bother to explain as they are trivial). Follow these steps in order to invoke a service via the API:
다음의 bare-essentials VB 코드는 API를 사용하는 것을 요구한다. 이것은 이 페이지 더 아래에서 다운로드 할 수 있는 VB 소스를 의역한 것이다. (바꾸어 설명하다) 우리는 SOAP-related 코드에서 손을 땔 것이지만, 여러분은 다운로드한 소스을 열어 기본적으로 같은 것을 볼수 있지만, 배열하고 클라이언트의 GUI를 다르는 좀 더 많은 것을 해야 한다. API를 통해서 서비스를 인보크 하기 위해 이러한 과정을 밟아야 한다.
* Define some constants which will be used to build the SOAP Envelope (if you want to know more about these URLs see the section on SOAP Messages) as well as your service identification data (SOAP Server URL, Service URI and service method name).
여러분의 서비스의 동일한 데이터 뿐만아니라 SOAP Envelope 를 빌드하여 사용할 수 있는 어떠한 일정한 것을 정의 해야 한다.
Private Const ENC = "http://schemas.xmlsoap.org/soap/encoding/"
Private Const XSI = "http://www.w3.org/1999/XMLSchema-instance"
Private Const XSD = "http://www.w3.org/1999/XMLSchema"
URL = "http://localhost:8080/soap/servlet/rpcrouter"
URI = "urn:QuotationService"
Method = "getQuotationsByAuthor"
* Instantiate your SOAP Connector, Serializer and Reader. The Connector will handle the HTTP Connection, the Serializer will help you build the SOAP Envelope and the Reader will help you to access the result.
여러분의 SOAP Connector, Serializer and Reader 초기화 해야 한다. 이 커넥터는 HTTP 커넥션으로 다룰 것이다. Serializer 는 여러분이 SOAP Envelope를 빌드 하는것을 도와 줄 것이며 Reader는 여러분이 그 결과를 사용할 수 있게 도와준다.
Dim Connector As SoapConnector
Dim Serializer As SoapSerializer
Dim Reader As SoapReader
Set Connector = New HttpConnector
Set Serializer = New SoapSerializer
Set Reader = New SoapReader
* Prepare the Connector to talk to the SOAP Server. Note that the "SoapAction" data is not consequential on the server side so the contents can be anything at all - It is a good idea to set it to the URI and Method name for easier identification when you are debugging and reading the SOAP messages.
사전에 SOAP Server의 커넥터를 준비 해야 한다. "SoapAction" 데이타는 서버사이드에서는 당연하지 않지만, 그 내용은 그 어떠한 모든 것을 할 수 있다. 이것은 여러분이 SOAP 메시지를 읽고 디버깅할 때 좀 더 쉽게 확인할 수 있는 URI과 메소드 이름을 세트 하는 좋은 생각이다.
Connector.Property("EndPointURL") = URL
Call Connector.Connect
Connector.Property("SoapAction") = URI & "#" & Method
Call Connector.BeginMessage
* Associate your Serializer with your Connector.
여러분의 Serialize와 Connector를 관련시키다.
Serializer.Init Connector.InputStream
* Start the SOAP Envelope and specify the Encoding and XML-Schema.
SOAP Envelope를 시작하고 Encoding 과 XML -Schema를 명시한다.
Serializer.startEnvelope , ENC
Serializer.SoapNamespace "xsi", XSI
Serializer.SoapNamespace "SOAP-ENC", ENC
Serializer.SoapNamespace "xsd", XSD
* Start the body of the message - the root element is always the Service URI and method.
메시지의 바디를 시작한다. 루트 원소는 항상 서비스 URI와 메소드여야 한다.
Serializer.startBody
Serializer.startElement Method, URI, , "method"
* Write each method parameter out as a child to the root element.
루트 원소에 차일드는 각각의 메소드 파라미터에 대해 적어야 한다.
Serializer.startElement "Author"
Serializer.SoapAttribute "type", , "xsd:string", "xsi"
Serializer.writeString "Wilde, Oscar"
Serializer.endElement
* End the root element, the body and the envelope.
루트 원소의 끝에 body와 envelope를 위치한다.
Serializer.endElement
Serializer.endBody
Serializer.endEnvelope
* Ending the message causes it to be sent.
보냈다면 메시지 끝을 종료 해야 한다.
Connector.EndMessage
* Load the result into the Reader.
리더안에 결과를 로드 하라.
Reader.Load Connector.OutputStream
* If no fault loading the Reader then you can go ahead and pull the result of the invocation out of the DOM (Document Object Model) contained in the reader. There are many ways to do this ranging from methods highly specialised to the task at hand (and thus quite efficient) to more general and reusable methods that are not so efficient (like the method you will see in the downloadable source).
만약 결점없이 리더를 로드하면 여러분은 실행할 수 있고 리더안에 포함된 DOM 밖에서 인보케이션(주문?)의 결과를 끌어 당길 것이다. 여기에
If Not Reader.Fault Is Nothing Then
MsgBox Reader.faultstring.text, vbExclamation
Else
Set Result = Reader.DOM
//parse the DOM to extract the result set
End If
Writing the Client
First, download the source code zip file (the VB forms) for the Visual Basic Quotation Service Client. Extract the entire contents of the zip to the directory of your choice. Then open up Visual Basic and Create a new project (of type Standard EXE), remove the default form and add ALL THREE downloaded forms to the project. Ensure that you set the main form (main.frm) to be the Startup Object (use: Project Properties / General tab). Before running you will need to add references to the MS SOAP Toolkit DLLs. Once done they should look like this (the last four references being the ones to add):
client-4 diagram-1
Running the Client
You can either compile the project into an executable and run that or just run it from within Visual Basic. The interface is fairly straightforward and does not require any explanation. Once again, the code as is presumes that you have the Quotation Service running on your machine (at localhost:8080). If this is not the case then you can run the clients against our demo SOAP server. To do this simply replace localhost:8080 with services.xmethods.net in the in the space provided for the URL. For more information on our demo server, refer to the Demo Section.
Incorporating into Microsoft Excel
It is relatively simple to incorporate the code that we have just written into Microsoft Excel as a VB Macro. Download and open up this Excel Spreadsheet [note: right click this link and save the file to your hard drive] to have an idea how this is done (note that, if asked by Excel, you will have to enable macros for this to run correctly). Take a look at the code behind the "Get All Quotations" button. Notice that all we really did was take the code from the VB example above and change it to read input and push output to the excel sheet rather than the VB form. Only the getAllQuotations method is implemented in this spreadsheet. It is left as an exercise for the reader to implement the other methods. For those not familiar with the VB Macro interface you will need to add the "Control Toolbox" Toolbar (see Tools/Customize/Toolbars), then activate Design Mode by hitting the blue set-square button. You will then be able to right click the "Get All Quotations" button on the spreadsheet and view the related code. Notice that the same four SOAP Toolkit DLLs have been added as project references (on the VB Macro Editor see Tools/References). Again, the code as is presumes that you have the Quotation Service running on your machine (at localhost:8080). If this is not the case then you can run the clients against our demo SOAP server. To do this simply replace localhost:8080 with services.xmethods.net in the in the space provided for the URL.
[ Nicholas Quaine ]