VB6またはASPでWebサービスを実施します
Webサービステクノロジーにより、異種のコンピューティング環境がデータと通信を共有して、情報の一貫性を実現できます。使用できます
HTTP Post/Get Protocol、SOAPプロトコルはWebサービスを呼び出します。
1. SOAPプロトコルを使用して、VB6でWebサービスを呼び出す
;最初に.NETを使用して、シンプルなWebサービスをリリースします
<webmethod()> _
パブリック関数GetString(byval str as string)
Hello Worldを返し、&str&!
エンド関数
Webサービスには、文字列を返すための1つのGetStringメソッドのみが含まれています。このWebサービスを呼び出すと、.smxページに送信されたSOAPメッセージは::
<?xmlバージョン= 1.0 encoding = utf-8?>
<SOAP:Envelope XMLNS:XSI = http://www.w3.org/2001/xmlschema-instance
xmlns:xsd = http://www.w3.org/2001/xmlschema xmlns:soap = http://
schemas.xmlsoap.org/soap/envelope/>
<SOAP:body>
<getString xmlns = http://tempuri.org/testwebservice/service1>
<str>文字列</strong
</getString>
</soap:body>
</soap:envelope>
返された石鹸メッセージは次のとおりです。
<?xmlバージョン= 1.0 encoding = utf-8?>
<SOAP:Envelope XMLNS:XSI = http://www.w3.org/2001/xmlschema-instance
xmlns:xsd = http://www.w3.org/2001/xmlschema xmlns:soap =
http://schemas.xmlsoap.org/soap/envelope/>
<SOAP:body>
<getStringResponse xmlns = http://tempuri.org/testwebservice/service1>
<getStringrsult> string </getStringResult>
</getStringResponse>
</soap:body>
</soap:envelope>
VB6のこのシンプルなWebサービスは、xmlhttpプロトコルを使用して.asmxページに送信できます
実装するためにSOAPを送信します。
VB6では、シンプルなプロジェクトを構築すると、この図にインターフェイスが表示されます
単一のWebサービス
文字列としてdim strxml
文字列としての薄暗いstr
str = text2.text
'石鹸メッセージを定義します
strxml = <?xmlバージョン= '1.0' encoding = 'utf-8'?> <soap:envelope
xmlns:xsi = 'http://www.w3.org/2001/xmlschema-instance'
xmlns:xsd = 'http://www.w3.org/2001/xmlschema'
xmlns:soap = 'http://schemas.xmlsoap.org/soap/envelope/'> <sap:body> <
</strong </getString> </soap:body> </soap:envelope>
'HTTPオブジェクトを定義し、サーバーに投稿メッセージを送信します
msxml2.serverxmlhttp40としてdim h
'XMLのドキュメントオブジェクトを定義したり、手書きまたは受け入れられたXMLコンテンツをXMLオブジェクトに変換したりします
msxml2.document40としてdim x
'XMLオブジェクトを初期化します
x = new msxml2.document40を設定します
'手書きの石鹸弦をXMLオブジェクトに変換します
x.loadxml strxml
'HTTPオブジェクトを初期化します
h = new msxml2.serverxmlhttp40を設定します
'指定されたURLに投稿メッセージを送信します
H.Open Post、http://localhost/testwebservice/service1.asmx、false
H.SetRequestHeaderコンテンツタイプ、テキスト/XML
H.SEND(STRXML)
H.ReadyState <> 4
ウェンド
'返されたXML情報を表示します
text1.text = h.responsetext
'返されたXML情報を分析し、返品値を表示します
x = new msxml2.document40を設定します
x.loadxml text1.text
text1.text = x.childnodes(1).text
テキストボックスに「中国」を入力し、ボタンをクリックすると、以下のテキストボックスに「Hello World、China」を表示できます。図に示すように表示します: