⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helloworld.vb

📁 wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重推荐,电子书,电子书下载
💻 VB
字号:
Imports System.Text
Imports System.Net

Public Class frmWSTest
	Private wsOrders As DCOrdersWS.DCOrdersWS

	Private Sub btnInvoke_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInvoke.Click
		'Dim wsOrders As DCOrdersWS.DCOrdersWS = New DCOrdersWS.DCOrdersWS

		If txtURL.Text.Contains("http://") And txtURL.Text.Contains(".asmx") Then
			wsOrders.Url = txtURL.Text
		Else
			txtURL.Text = wsOrders.Url
		End If
		If Val(txtTimeout.Text) > 0 Then
			wsOrders.Timeout = CType(txtTimeout.Text, Integer)
		Else
			txtTimeout.Text = wsOrders.Timeout.ToString
		End If
		If txtUserAgent.Text.Length > 0 Then
			wsOrders.UserAgent = txtUserAgent.Text
		Else
			txtUserAgent.Text = wsOrders.UserAgent
		End If

		If chkSoap12.Checked Then
			'Use SOAP 1.2
			wsOrders.SoapVersion = Web.Services.Protocols.SoapProtocolVersion.Soap12
		Else
			'Use SOAP 1.1 (the default)
			wsOrders.SoapVersion = Web.Services.Protocols.SoapProtocolVersion.Soap11
        End If

        If chkGZIP.Checked Then
            wsOrders.EnableDecompression = True
        Else
            wsOrders.EnableDecompression = False
        End If

		If chkCredentials.Checked Then
			If optWindows.Checked Then
				'Windows authentication for current user
				wsOrders.Credentials = CredentialCache.DefaultCredentials
			Else
				'Use Basic or Digest authentication
				Dim wsCredCache As New CredentialCache
				Dim wsCred As New NetworkCredential
				wsCred.UserName = txtUserName.Text
				wsCred.Password = txtPassword.Text
				Dim strAuthType As String = Nothing
				If optBasic.Checked Then
					strAuthType = "Basic"
				Else
					'Basic credentials don't require a domain name
					wsCred.Domain = txtDomain.Text
					strAuthType = "Digest"
				End If
				wsCredCache.Add(New Uri(wsOrders.Url), strAuthType, wsCred)
				wsOrders.Credentials = wsCredCache
			End If
		End If

		Try
			Dim lngTime As Long = Now.Ticks
			'Invoke the HelloWorld WebMethod
			txtResult.Text = wsOrders.HelloWorld
			txtTime.Text = Format((Now.Ticks - lngTime) / 10000000, "0.000")
		Catch exc As Exception
			txtResult.Text = ""
			txtTime.Text = ""
			MsgBox(exc.Message, MsgBoxStyle.Exclamation, "Error Invoking WebMethod")
		End Try
	End Sub

	Private Sub frmWSTest_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		wsOrders = New DCOrdersWS.DCOrdersWS
		txtURL.Text = wsOrders.Url
        txtTimeout.Text = 10000 'wsOrders.Timeout.ToString = 100000 ms.
		txtUserAgent.Text = wsOrders.UserAgent
		txtDomain.Text = "DOMAIN"
		txtUserName.Text = "UserName"
        txtPassword.Text = "Password"
        chkCredentials.Checked = True 'Built-in Web server requires Windows authentication
	End Sub

    Private Sub chkGZIP_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkGZIP.CheckedChanged
        txtResult.Text = ""
    End Sub

    Private Sub chkSoap12_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSoap12.CheckedChanged
        txtResult.Text = ""
    End Sub

	Private Sub chkCredentials_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCredentials.CheckedChanged
		txtResult.Text = ""
		If chkCredentials.Checked Then
			gbAuthentication.Visible = True
		Else
			gbAuthentication.Visible = False
		End If
	End Sub

    Private Sub optBasic_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optBasic.CheckedChanged
        txtResult.Text = ""
        If optBasic.Checked Then
            txtDomain.Enabled = True
            txtUserName.Enabled = True
            txtPassword.Enabled = True
        End If
    End Sub

    Private Sub optDigest_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optDigest.CheckedChanged
        txtResult.Text = ""
        If optDigest.Checked Then
            txtDomain.Enabled = True
            txtUserName.Enabled = True
            txtPassword.Enabled = True
        End If
    End Sub

    Private Sub optWindows_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optWindows.CheckedChanged
        txtResult.Text = ""
        If optWindows.Checked Then
            txtDomain.Enabled = False
            txtUserName.Enabled = False
            txtPassword.Enabled = False
        End If
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -