VB.NET调用WebService时报错

Standard

加入wsDataContent.Credentials = System.Net.CredentialCache.DefaultCredentials即正常(*号标出)

‘WebService源文件
Private dsData As DataSet

Private Sub LoadDataSet()

Dim successful As Boolean
successful = True

Dim errorMessage As String
errorMessage = “”

dsData = New DataSet
dsData.DataSetName = “db”

Try
Dim dbConn As New OleDbConnection
With dbConn
.ConnectionString = “PROVIDER=SQLOLEDB;Server=(local);DATABASE=db_name;UID=sa;PWD=;”
.Open()
End With

Try
Dim dbCmdUser As New OleDbCommand
dbCmdUser.Connection = dbConn
dbCmdUser.CommandText = “SELECT * FROM tb_user”
Dim dbCmdProject As New OleDbCommand
dbCmdProject.Connection = dbConn
dbCmdProject.CommandText = “SELECT * FROM tb_project”
Dim dbCmdJob As New OleDbCommand
dbCmdJob.Connection = dbConn
dbCmdJob.CommandText = “SELECT * FROM tb_job”
Dim dbCmdTopic As New OleDbCommand
dbCmdTopic.Connection = dbConn
dbCmdTopic.CommandText = “SELECT * FROM tb_topic”

Dim dbAdUser As New OleDbDataAdapter
dbAdUser.SelectCommand = dbCmdUser
Dim dbAdProject As New OleDbDataAdapter
dbAdProject.SelectCommand = dbCmdProject
Dim dbAdJob As New OleDbDataAdapter
dbAdJob.SelectCommand = dbCmdJob
Dim dbAdTopic As New OleDbDataAdapter
dbAdTopic.SelectCommand = dbCmdTopic

dbAdUser.Fill(dsData, “User”)
dbAdProject.Fill(dsData, “Project”)
dbAdJob.Fill(dsData, “Job”)
dbAdTopic.Fill(dsData, “Topic”)
Catch ex A* **ception
successful = False
errorMessage = ex.Message.ToString
errorMessage = “Error reading data.”
Finally
dbConn.Close()
End Try
Catch ex A* **ception
successful = False
errorMessage = “Error opening data connention.”
End Try

If Not successful Then
Throw New Exception(errorMessage)
End If
End Sub

<WebMethod()> _
Public Function getDataSet() As DataSet
LoadDataSet()
Return dsData
End Function

‘VB.NET窗体源文件
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim wsDataContent As DataContent
wsDataContent = New DataContent
‘***********www.yemaosheng.com***********’
wsDataContent.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim ds As DataSet
ds = wsDataContent.getDataSet()
dgMain.DataSource = ds
dgMain.DataMember = “User”
Catch ex A* **ception
MsgBox(ex.Message, , “出错提示”)
End Try
End Sub