学习SOAP一个不错的简单例子(二)

客户端说明:
         
         在客户端用到了Microsoft Internet Transfer Control, version 6.0 ,请先从工具箱中引入。
         具体请参看代码,主要是SOAP的组装和提取,对于初学者很有帮助。
         代码没有对出错作任何检查,所以测试时数据要求准确输入,特别是DateTime型数据请以“yyyy-MM-ddTHH:mm:ss”格式输入。程序在 Windows XP SP2 + VS.Net 2003 环境下调试正常。

         存在问题,在SOAP传输时,中文字符不能正常显示,都是采用的UTF-8,我不知道是什么原因。
         有人知道,请告诉我 谢谢了。
        
客户端代码:
Option Strict Off
Option Explicit Off

Imports System
Imports System.Xml

Namespace TAUSoapClient
    
Public Class Form1
        
Inherits System.Windows.Forms.Form
        
Private components As System.ComponentModel.IContainer
#Region 
" Windows Form Designer generated code "
        ' Required by the Win Form Designer
        Private WithEvents txtOrig As System.Windows.Forms.TextBox
        
Private WithEvents Label13 As System.Windows.Forms.Label
        
Private WithEvents Label10 As System.Windows.Forms.Label
        
Private WithEvents txtEnd As System.Windows.Forms.TextBox
        
Private WithEvents txtAgent As System.Windows.Forms.TextBox
        
Private WithEvents txtPrice As System.Windows.Forms.TextBox
        
Private WithEvents txtAL As System.Windows.Forms.TextBox
        
Private WithEvents Label12 As System.Windows.Forms.Label
        
Private WithEvents Label11 As System.Windows.Forms.Label
        
Private WithEvents Label9 As System.Windows.Forms.Label
        
Private WithEvents btnUpload As System.Windows.Forms.Button
        
Private WithEvents txtDays As System.Windows.Forms.TextBox
        
Private WithEvents Label8 As System.Windows.Forms.Label
        
Private WithEvents txtDest As System.Windows.Forms.TextBox
        
Private WithEvents Label7 As System.Windows.Forms.Label
        
Private WithEvents Label6 As System.Windows.Forms.Label
        
Private WithEvents txtId As System.Windows.Forms.TextBox
        
Private WithEvents txtPktInfo As System.Windows.Forms.TextBox
        
Private WithEvents GroupBox2 As System.Windows.Forms.GroupBox
        
Private WithEvents txtStartDate As System.Windows.Forms.TextBox
        
Private WithEvents Label5 As System.Windows.Forms.Label
        
Private WithEvents Label4 As System.Windows.Forms.Label
        
Private WithEvents txtPktId As System.Windows.Forms.TextBox
        
Private WithEvents GroupBox1 As System.Windows.Forms.GroupBox
        
Public ToolTip1 As System.Windows.Forms.ToolTip
        
Public WithEvents SOAPRespReceived As System.Windows.Forms.TextBox
        
Private WithEvents SOAPReqSent As System.Windows.Forms.TextBox
        
Public WithEvents txtURL As System.Windows.Forms.TextBox
        
Public WithEvents Label3 As System.Windows.Forms.Label
        
Public WithEvents Label2 As System.Windows.Forms.Label
        
Public WithEvents Label1 As System.Windows.Forms.Label

        
Public Sub New()
        
' Form overrides dispose to clean up the component list.
        ' Public Overloads Sub Dispose()
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            
If disposing Then
                
If Not (components Is NothingThen
                    components.Dispose()
                
End If
            
End If
            
MyBase.Dispose(disposing)
        
End Sub

        
' The main entry point for the application
        Shared Sub Main()
            System.Windows.Forms.Application.Run(
New Form1)
        
End Sub

        
' NOTE: The following procedure is required by the Win Form Designer
        ' It can be modified using the Win Form Designer.
        ' Do not modify it using the code editor.
        Friend WithEvents Inet1 As AxInetCtlsObjects.AxInet
        
Private WithEvents btnGetNewDeal As System.Windows.Forms.Button
        
Private WithEvents BtnGetPacket As System.Windows.Forms.Button

        
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.components 
= New System.ComponentModel.Container
            
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
            Me.txtPrice 
= New System.Windows.Forms.TextBox
            Me.btnUpload 
= New System.Windows.Forms.Button
            Me.Label11 
= New System.Windows.Forms.Label
            Me.Label10 
= New System.Windows.Forms.Label
            Me.Label13 
= New System.Windows.Forms.Label
            Me.Label12 
= New System.Windows.Forms.Label
            Me.txtURL 
= New System.Windows.Forms.TextBox
            Me.txtStartDate 
= New System.Windows.Forms.TextBox
            Me.txtOrig 
= New System.Windows.Forms.TextBox
            Me.Label8 
= New System.Windows.Forms.Label
            Me.Label9 
= New System.Windows.Forms.Label
            Me.Label4 
= New System.Windows.Forms.Label
            Me.Label5 
= New System.Windows.Forms.Label
            Me.Label6 
= New System.Windows.Forms.Label
            Me.Label7 
= New System.Windows.Forms.Label
            Me.Label1 
= New System.Windows.Forms.Label
            Me.Label2 
= New System.Windows.Forms.Label
            Me.txtAgent 
= New System.Windows.Forms.TextBox
            Me.GroupBox1 
= New System.Windows.Forms.GroupBox
            Me.txtPktInfo 
= New System.Windows.Forms.TextBox
            Me.txtPktId 
= New System.Windows.Forms.TextBox
            Me.BtnGetPacket 
= New System.Windows.Forms.Button
            Me.btnGetNewDeal 
= New System.Windows.Forms.Button
            Me.GroupBox2 
= New System.Windows.Forms.GroupBox
            Me.txtEnd 
= New System.Windows.Forms.TextBox
            Me.txtAL 
= New System.Windows.Forms.TextBox
            Me.txtDays 
= New System.Windows.Forms.TextBox
            Me.txtDest 
= New System.Windows.Forms.TextBox
            Me.txtId 
= New System.Windows.Forms.TextBox
            Me.Label3 
= New System.Windows.Forms.Label
            Me.SOAPReqSent 
= New System.Windows.Forms.TextBox
            Me.ToolTip1 
= New System.Windows.Forms.ToolTip(Me.components)
            Me.SOAPRespReceived 
= New System.Windows.Forms.TextBox
            Me.Inet1 
= New AxInetCtlsObjects.AxInet
            Me.GroupBox1.SuspendLayout()
            Me.GroupBox2.SuspendLayout()
            
CType(Me.Inet1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            
'
            'txtPrice
            '
            Me.txtPrice.Location = New System.Drawing.Point(39240)
            Me.txtPrice.Name 
= "txtPrice"
            Me.txtPrice.Size = New System.Drawing.Size(8021)
            Me.txtPrice.TabIndex 
= 12
            Me.txtPrice.Text 
= ""
            '
            'btnUpload
            '
            Me.btnUpload.Location = New System.Drawing.Point(40872)
            Me.btnUpload.Name 
= "btnUpload"
            Me.btnUpload.TabIndex = 6
            Me.btnUpload.Text 
= "Upload"
            '
            'Label11
            '
            Me.Label11.Location = New System.Drawing.Point(16048)
            Me.Label11.Name 
= "Label11"
            Me.Label11.Size = New System.Drawing.Size(5616)
            Me.Label11.TabIndex 
= 9
            Me.Label11.Text 
= "Air Line"
            '
            'Label10
            '
            Me.Label10.Location = New System.Drawing.Point(29624)
            Me.Label10.Name 
= "Label10"
            Me.Label10.Size = New System.Drawing.Size(7216)
            Me.Label10.TabIndex 
= 13
            Me.Label10.Text 
= "Offer Ends:"
            '
            'Label13
            '
            Me.Label13.Location = New System.Drawing.Point(872)
            Me.Label13.Name 
= "Label13"
            Me.Label13.Size = New System.Drawing.Size(3216)
            Me.Label13.TabIndex 
= 15
            Me.Label13.Text 
= "From:"
            '
            'Label12
            '
            Me.Label12.Location = New System.Drawing.Point(16072)
            Me.Label12.Name 
= "Label12"
            Me.Label12.Size = New System.Drawing.Size(4023)
            Me.Label12.TabIndex 
= 10
            Me.Label12.Text 
= "Agent"
            '
            'txtURL
            '
            Me.txtURL.AutoSize = False
            Me.txtURL.BackColor 
= System.Drawing.SystemColors.Window
            Me.txtURL.Cursor 
= System.Windows.Forms.Cursors.Default
            Me.txtURL.ForeColor 
= System.Drawing.SystemColors.WindowText
            Me.txtURL.Location 
= New System.Drawing.Point(1640)
            Me.txtURL.Name 
= "txtURL"
            Me.txtURL.RightToLeft = System.Windows.Forms.RightToLeft.No
            Me.txtURL.Size 
= New System.Drawing.Size(33625)
            Me.txtURL.TabIndex 
= 0
            Me.txtURL.Text 
= "http://localhost/TAUWebService/Service1.asmx"
            '
            'txtStartDate
            '
            Me.txtStartDate.Location = New System.Drawing.Point(8896)
            Me.txtStartDate.Name 
= "txtStartDate"
            Me.txtStartDate.Size = New System.Drawing.Size(16821)
            Me.txtStartDate.TabIndex 
= 14
            Me.txtStartDate.Text 
= "yyyy-MM-ddTHH:mm:ss"
            '
            'txtOrig
            '
            Me.txtOrig.Location = New System.Drawing.Point(4864)
            Me.txtOrig.Name 
= "txtOrig"
            Me.txtOrig.Size = New System.Drawing.Size(9621)
            Me.txtOrig.TabIndex 
= 16
            Me.txtOrig.Text 
= ""
            '
            'Label8
            '
            Me.Label8.Location = New System.Drawing.Point(16024)
            Me.Label8.Name 
= "Label8"
            Me.Label8.Size = New System.Drawing.Size(3216)
            Me.Label8.TabIndex 
= 4
            Me.Label8.Text 
= "Days:"
            '
            'Label9
            '
            Me.Label9.Location = New System.Drawing.Point(29648)
            Me.Label9.Name 
= "Label9"
            Me.Label9.TabIndex = 7
            Me.Label9.Text 
= "Starting Price:"
            '
            'Label4
            '
            Me.Label4.Location = New System.Drawing.Point(824)
            Me.Label4.Name 
= "Label4"
            Me.Label4.Size = New System.Drawing.Size(8023)
            Me.Label4.TabIndex 
= 11
            Me.Label4.Text 
= "Packet ID:"
            '
            'Label5
            '
            Me.Label5.Location = New System.Drawing.Point(0104)
            Me.Label5.Name 
= "Label5"
            Me.Label5.Size = New System.Drawing.Size(10024)
            Me.Label5.TabIndex 
= 13
            Me.Label5.Text 
= "Offer Starts:"
            '
            'Label6
            '
            Me.Label6.Location = New System.Drawing.Point(824)
            Me.Label6.Name 
= "Label6"
            Me.Label6.Size = New System.Drawing.Size(2416)
            Me.Label6.TabIndex 
= 1
            Me.Label6.Text 
= "ID:"
            '
            'Label7
            '
            Me.Label7.Location = New System.Drawing.Point(848)
            Me.Label7.Name 
= "Label7"
            Me.Label7.Size = New System.Drawing.Size(2416)
            Me.Label7.TabIndex 
= 2
            Me.Label7.Text 
= "To:"
            '
            'Label1
            '
            Me.Label1.BackColor = System.Drawing.SystemColors.Control
            Me.Label1.ForeColor 
= System.Drawing.SystemColors.ControlText
            Me.Label1.Location 
= New System.Drawing.Point(1616)
            Me.Label1.Name 
= "Label1"
            Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
            Me.Label1.Size 
= New System.Drawing.Size(20925)
            Me.Label1.TabIndex 
= 1
            Me.Label1.Text 
= "Travel Agency Union Service:"
            '
            'Label2
            '
            Me.Label2.BackColor = System.Drawing.SystemColors.Control
            Me.Label2.ForeColor 
= System.Drawing.SystemColors.ControlText
            Me.Label2.Location 
= New System.Drawing.Point(24352)
            Me.Label2.Name 
= "Label2"
            Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
            Me.Label2.Size 
= New System.Drawing.Size(15217)
            Me.Label2.TabIndex 
= 4
            Me.Label2.Text 
= "SOAP Request Sent:"
            '
            'txtAgent
            '
            Me.txtAgent.Location = New System.Drawing.Point(21664)
            Me.txtAgent.Name 
= "txtAgent"
            Me.txtAgent.Size = New System.Drawing.Size(6421)
            Me.txtAgent.TabIndex 
= 14
            Me.txtAgent.Text 
= ""
            '
            'GroupBox1
            '
            Me.GroupBox1.Controls.Add(Me.txtPktInfo)
            Me.GroupBox1.Controls.Add(Me.txtStartDate)
            Me.GroupBox1.Controls.Add(Me.Label5)
            Me.GroupBox1.Controls.Add(Me.Label4)
            Me.GroupBox1.Controls.Add(Me.txtPktId)
            Me.GroupBox1.Controls.Add(Me.BtnGetPacket)
            Me.GroupBox1.Controls.Add(Me.btnGetNewDeal)
            Me.GroupBox1.Location 
= New System.Drawing.Point(1680)
            Me.GroupBox1.Name 
= "GroupBox1"
            Me.GroupBox1.Size = New System.Drawing.Size(536168)
            Me.GroupBox1.TabIndex 
= 10
            Me.GroupBox1.TabStop 
= False
            Me.GroupBox1.Text 
= "Get Travel Packet Info"
            '
            'txtPktInfo
            '
            Me.txtPktInfo.Location = New System.Drawing.Point(28016)
            Me.txtPktInfo.Multiline 
= True
            Me.txtPktInfo.Name 
= "txtPktInfo"
            Me.txtPktInfo.ReadOnly = True
            Me.txtPktInfo.ScrollBars 
= System.Windows.Forms.ScrollBars.Both
            Me.txtPktInfo.Size 
= New System.Drawing.Size(248136)
            Me.txtPktInfo.TabIndex 
= 15
            Me.txtPktInfo.Text 
= ""
            '
            'txtPktId
            '
            Me.txtPktId.Location = New System.Drawing.Point(8824)
            Me.txtPktId.Name 
= "txtPktId"
            Me.txtPktId.Size = New System.Drawing.Size(16821)
            Me.txtPktId.TabIndex 
= 10
            Me.txtPktId.Text 
= ""
            '
            'BtnGetPacket
            '
            Me.BtnGetPacket.Location = New System.Drawing.Point(16056)
            Me.BtnGetPacket.Name 
= "BtnGetPacket"
            Me.BtnGetPacket.Size = New System.Drawing.Size(9623)
            Me.BtnGetPacket.TabIndex 
= 9
            Me.BtnGetPacket.Text 
= "Get Packet"
            '
            'btnGetNewDeal
            '
            Me.btnGetNewDeal.Location = New System.Drawing.Point(160128)
            Me.btnGetNewDeal.Name 
= "btnGetNewDeal"
            Me.btnGetNewDeal.Size = New System.Drawing.Size(9623)
            Me.btnGetNewDeal.TabIndex 
= 12
            Me.btnGetNewDeal.Text 
= "Get New Deals"
            '
            'GroupBox2
            '
            Me.GroupBox2.Controls.Add(Me.txtOrig)
            Me.GroupBox2.Controls.Add(Me.Label13)
            Me.GroupBox2.Controls.Add(Me.Label10)
            Me.GroupBox2.Controls.Add(Me.txtEnd)
            Me.GroupBox2.Controls.Add(Me.txtAgent)
            Me.GroupBox2.Controls.Add(Me.txtPrice)
            Me.GroupBox2.Controls.Add(Me.txtAL)
            Me.GroupBox2.Controls.Add(Me.Label12)
            Me.GroupBox2.Controls.Add(Me.Label11)
            Me.GroupBox2.Controls.Add(Me.Label9)
            Me.GroupBox2.Controls.Add(Me.btnUpload)
            Me.GroupBox2.Controls.Add(Me.txtDays)
            Me.GroupBox2.Controls.Add(Me.Label8)
            Me.GroupBox2.Controls.Add(Me.txtDest)
            Me.GroupBox2.Controls.Add(Me.Label7)
            Me.GroupBox2.Controls.Add(Me.Label6)
            Me.GroupBox2.Controls.Add(Me.txtId)
            Me.GroupBox2.Location 
= New System.Drawing.Point(16248)
            Me.GroupBox2.Name 
= "GroupBox2"
            Me.GroupBox2.Size = New System.Drawing.Size(536104)
            Me.GroupBox2.TabIndex 
= 11
            Me.GroupBox2.TabStop 
= False
            Me.GroupBox2.Text 
= "Upload Packet"
            '
            'txtEnd
            '
            Me.txtEnd.Location = New System.Drawing.Point(39216)
            Me.txtEnd.Name 
= "txtEnd"
            Me.txtEnd.Size = New System.Drawing.Size(13621)
            Me.txtEnd.TabIndex 
= 12
            Me.txtEnd.Text 
= "yyyy-MM-ddTHH:mm:ss"
            '
            'txtAL
            '
            Me.txtAL.Location = New System.Drawing.Point(21640)
            Me.txtAL.Name 
= "txtAL"
            Me.txtAL.Size = New System.Drawing.Size(6421)
            Me.txtAL.TabIndex 
= 11
            Me.txtAL.Text 
= ""
            '
            'txtDays
            '
            Me.txtDays.Location = New System.Drawing.Point(21616)
            Me.txtDays.Name 
= "txtDays"
            Me.txtDays.Size = New System.Drawing.Size(6421)
            Me.txtDays.TabIndex 
= 5
            Me.txtDays.Text 
= ""
            '
            'txtDest
            '
            Me.txtDest.Location = New System.Drawing.Point(4840)
            Me.txtDest.Name 
= "txtDest"
            Me.txtDest.Size = New System.Drawing.Size(9621)
            Me.txtDest.TabIndex 
= 3
            Me.txtDest.Text 
= ""
            '
            'txtId
            '
            Me.txtId.Location = New System.Drawing.Point(4816)
            Me.txtId.Name 
= "txtId"
            Me.txtId.Size = New System.Drawing.Size(9621)
            Me.txtId.TabIndex 
= 0
            Me.txtId.Text 
= ""
            '
            'Label3
            '
            Me.Label3.BackColor = System.Drawing.SystemColors.Control
            Me.Label3.ForeColor 
= System.Drawing.SystemColors.ControlText
            Me.Label3.Location 
= New System.Drawing.Point(24472)
            Me.Label3.Name 
= "Label3"
            Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
            Me.Label3.Size 
= New System.Drawing.Size(15217)
            Me.Label3.TabIndex 
= 5
            Me.Label3.Text 
= "SOAP Response Received:"
            '
            'SOAPReqSent
            '
            Me.SOAPReqSent.AutoSize = False
            Me.SOAPReqSent.BackColor 
= System.Drawing.SystemColors.Window
            Me.SOAPReqSent.Cursor 
= System.Windows.Forms.Cursors.Default
            Me.SOAPReqSent.ForeColor 
= System.Drawing.SystemColors.WindowText
            Me.SOAPReqSent.Location 
= New System.Drawing.Point(16376)
            Me.SOAPReqSent.Multiline 
= True
            Me.SOAPReqSent.Name 
= "SOAPReqSent"
            Me.SOAPReqSent.ReadOnly = True
            Me.SOAPReqSent.RightToLeft 
= System.Windows.Forms.RightToLeft.No
            Me.SOAPReqSent.ScrollBars 
= System.Windows.Forms.ScrollBars.Vertical
            Me.SOAPReqSent.Size 
= New System.Drawing.Size(53688)
            Me.SOAPReqSent.TabIndex 
= 14
            Me.SOAPReqSent.Text 
= ""
            '
            'SOAPRespReceived
            '
            Me.SOAPRespReceived.AutoSize = False
            Me.SOAPRespReceived.BackColor 
= System.Drawing.SystemColors.Window
            Me.SOAPRespReceived.Cursor 
= System.Windows.Forms.Cursors.Default
            Me.SOAPRespReceived.ForeColor 
= System.Drawing.SystemColors.WindowText
            Me.SOAPRespReceived.Location 
= New System.Drawing.Point(16488)
            Me.SOAPRespReceived.Multiline 
= True
            Me.SOAPRespReceived.Name 
= "SOAPRespReceived"
            Me.SOAPRespReceived.ReadOnly = True
            Me.SOAPRespReceived.RightToLeft 
= System.Windows.Forms.RightToLeft.No
            Me.SOAPRespReceived.ScrollBars 
= System.Windows.Forms.ScrollBars.Vertical
            Me.SOAPRespReceived.Size 
= New System.Drawing.Size(53688)
            Me.SOAPRespReceived.TabIndex 
= 3
            Me.SOAPRespReceived.Text 
= ""
            '
            'Inet1
            '
            Me.Inet1.Enabled = True
            Me.Inet1.Location 
= New System.Drawing.Point(304456)
            Me.Inet1.Name 
= "Inet1"
            Me.Inet1.OcxState = CType(resources.GetObject("Inet1.OcxState"), System.Windows.Forms.AxHost.State)
            Me.Inet1.Size 
= New System.Drawing.Size(3838)
            Me.Inet1.TabIndex 
= 15
            
'
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(614)
            Me.ClientSize 
= New System.Drawing.Size(600642)
            Me.Controls.Add(Me.Inet1)
            Me.Controls.Add(Me.GroupBox1)
            Me.Controls.Add(Me.GroupBox2)
            Me.Controls.Add(Me.txtURL)
            Me.Controls.Add(Me.SOAPReqSent)
            Me.Controls.Add(Me.SOAPRespReceived)
            Me.Controls.Add(Me.Label1)
            Me.Controls.Add(Me.Label2)
            Me.Controls.Add(Me.Label3)
            Me.Location 
= New System.Drawing.Point(423)
            Me.Name 
= "Form1"
            Me.Text = "Soap Client Example"
            Me.GroupBox1.ResumeLayout(False)
            Me.GroupBox2.ResumeLayout(
False)
            
CType(Me.Inet1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(
False)

        
End Sub

#
End Region

        
Protected Sub Form1_Click(ByVal sender As ObjectByVal e As System.EventArgs)

        
End Sub


        
Private soapRequestXML As String

        
Protected Sub clearTextBox(ByVal extraTxtBox As String)
            
If extraTxtBox = "GetNewDeal" Then
                txtPktId.Clear()
            
ElseIf extraTxtBox = "GetPacket" Then
                txtStartDate.Clear()
            
End If
            txtId.Clear()
            txtDest.Clear()
            txtEnd.Clear()
            txtPrice.Clear()
            txtAL.Clear()
            txtAgent.Clear()
            txtDays.Clear()
            txtOrig.Clear()
        
End Sub


        
Protected Overrides Sub Finalize()

        
End Sub


        
Private Sub btnGetPacket_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles BtnGetPacket.Click
            clearTextBox(
"GetPacket")
            soapRequestXML 
= "<?xml version=""1.0"" encoding=""utf-8"" ?> " & _
            
"<Envelope xmlns = " & _
            
"""http://schemas.xmlsoap.org/soap/envelope/"" >" & _
            
" <Body> " & _
            
"<GetPacketDetail " & _
            
"xmlns=""http://tempuri.org/""> " & _
            
"<packetId> NONE </packetId> " & _
            
"</GetPacketDetail> " & _
            
"</Body> " & _
            
"</Envelope>"

            If (txtPktId.Text = ""Then
                
MsgBox("Please input a packet ID!")
                
Return
            
End If

            
'Compose the soap message
            Dim parser As XmlDocument = New XmlDocument
            parser.LoadXml(soapRequestXML)

            
'Insert the packet id to the XML
            Dim elemList As XmlNodeList = _
                parser.GetElementsByTagName(
"packetId")
            elemList(
0).InnerText = txtPktId.Text

            
'Display the soap message
            SOAPReqSent.Text = parser.OuterXml

            
'Send soap message
            Inet1.Execute(txtURL.Text, "POST", _
                parser.OuterXml, 
"Content-Type: text/xml" _
                
& ControlChars.Cr & ControlChars.Lf _
                
& "SOAPAction: http://tempuri.org/GetPacketDetail")
        
End Sub


        
Private Sub Inet1_StateChanged(ByVal sender As ObjectByVal e As AxInetCtlsObjects.DInetEvents_StateChangedEvent) Handles Inet1.StateChanged
            
Dim txtPrice As Object

            
Dim buffer1, buffer2 As String
            
Dim DocIn As XmlDocument = New XmlDocument
            
Dim NodeList As XmlNodeList
            
Dim NodeList2 As XmlNodeList
            
Dim Node As XmlNode
            
Dim Node2 As XmlNode
            
If (e.state = 12Then

                
' Read data returned from server.
                buffer2 = Inet1.GetChunk(8192, buffer1)

                SOAPRespReceived.Text 
= buffer2

                
' Place into new XML document
                DocIn.LoadXml(buffer2)
                
Dim newline As String
                newline 
= ControlChars.Cr & ControlChars.Lf
                
Dim result As String
                result 
= ""
                ' Locate the return result.
                'If it is a packet detail, display it in the txtPkgInfo
                NodeList = DocIn.GetElementsByTagName("GetPacketDetailResult")
                
If Not NodeList.Count = 0 Then
                    txtPktInfo.Clear()
                
End If
                NodeList 
= DocIn.GetElementsByTagName("GetPacketDetailResult")

                
If Not NodeList.Count = 0 Then

                    
For Each Node In NodeList
                        NodeList2 
= Node.ChildNodes()
                        
For Each Node2 In NodeList2
                            txtPktInfo.AppendText(Node2.Name)
                            txtPktInfo.AppendText(
"")
                            txtPktInfo.AppendText(Node2.InnerText)
                            txtPktInfo.AppendText(newline)
                        
Next
                        txtPktInfo.AppendText(newline)
                    
Next

                
End If

                
'If it is a new packet result, display in the txtPkgInfo
                NodeList = DocIn.GetElementsByTagName("TravelPacket")
                
If Not NodeList.Count = 0 Then
                    txtPktInfo.Clear()
                
End If
                NodeList 
= DocIn.GetElementsByTagName("TravelPacket")
                
If Not NodeList.Count = 0 Then

                    txtPktInfo.Clear()
                    
For Each Node In NodeList
                        NodeList2 
= Node.ChildNodes()
                        
For Each Node2 In NodeList2
                            txtPktInfo.AppendText(Node2.Name)
                            txtPktInfo.AppendText(
"")
                            txtPktInfo.AppendText(Node2.InnerText)
                            txtPktInfo.AppendText(newline)
                        
Next
                        txtPktInfo.AppendText(newline)
                    
Next

                
End If

            
End If
        
End Sub


        
Private Sub btnUpload_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnUpload.Click
            
'Compose the soap message
            soapRequestXML = "<?xml version=""1.0"" ?> " & _
            
"<Envelope xmlns = ""http://schemas.xmlsoap.org/soap/envelope/"" > " & _
            
"<Body> " & _
            
"<UploadPacket xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" " & _
            
"xmlns=""http://tempuri.org/""> " & _
            
"<TravelPacket> </TravelPacket> " & _
            
"</UploadPacket> " & _
            
"</Body> </Envelope>"

            Dim parser As XmlDocument = New XmlDocument
            parser.LoadXml(soapRequestXML)

            
'Insert individual fields.
            Dim uploadNode As XmlNode
            uploadNode 
= parser.GetElementsByTagName("UploadPacket")(0)

            
Dim propertyNode As XmlNode
            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "id""http://tempuri.org/")
            propertyNode.InnerText 
= txtId.Text
            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "destination""http://tempuri.org/")
            propertyNode.InnerText 
= txtDest.Text
            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "offerEnds""http://tempuri.org/")
            propertyNode.InnerText 
= txtEnd.Text

            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "startingPrice""http://tempuri.org/")
            propertyNode.InnerText 
= txtPrice.Text
            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "airline""http://tempuri.org/")
            propertyNode.InnerText 
= txtAL.Text
            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "agent""http://tempuri.org/")
            propertyNode.InnerText 
= txtAgent.Text
            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "numOfDays""http://tempuri.org/")
            propertyNode.InnerText 
= txtDays.Text
            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "originCity""http://tempuri.org/")
            propertyNode.InnerText 
= txtOrig.Text
            uploadNode.AppendChild(propertyNode)

            propertyNode 
= parser.CreateNode(XmlNodeType.Element, "offerStarts""http://tempuri.org/")
            propertyNode.InnerText 
= Today.ToString("s")
            uploadNode.AppendChild(propertyNode)

            
'Display the soap message
            SOAPReqSent.Text = parser.OuterXml

            
'Send soap message
            Inet1.Execute(txtURL.Text, "POST", parser.OuterXml, "Content-Type: text/xml; charset=utf-8" & ControlChars.Cr & ControlChars.Lf & "SOAPAction: http://tempuri.org/UploadPacket")

        
End Sub


        
Private Sub btnGetNewDeal_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles btnGetNewDeal.Click
            clearTextBox(
"GetNewDeal")
            soapRequestXML 
= "<?xml version=""1.0"" encoding=""utf-8"" ?> <Envelope xmlns = ""http://schemas.xmlsoap.org/soap/envelope/"" > <Body> <GetNewPackets xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://tempuri.org/""><day></day> </GetNewPackets> </Body> </Envelope>"

            If txtStartDate.Text = "" Then
                txtStartDate.Text 
= Today.ToString("s")
            
End If

            
'Compose the soap message
            Dim parser As XmlDocument = New XmlDocument
            parser.LoadXml(soapRequestXML)

            
'Insert the start date to the XML
            Dim elemList As XmlNodeList = parser.GetElementsByTagName("day")
            elemList(
0).InnerText = txtStartDate.Text

            
'Display the soap message
            SOAPReqSent.Text = parser.OuterXml

            
'Send soap message
            Inet1.Execute(txtURL.Text, "POST", parser.OuterXml, _
            
"Content-Type: text/xml; charset=utf-8" _
            
& ControlChars.Cr & ControlChars.Lf _
            
& "SOAPAction: http://tempuri.org/GetNewPackets")
        
End Sub

    
End Class

End Namespace
posted on 2005-04-03 14:16  我在等待  阅读(1005)  评论(0编辑  收藏  举报