尝试连接到网络服务失败。
用户输入WebService的网址,在我的情况下是http://localhost:61302/WebService/XYZService.asmx
,输入用户名/登录信息(出于测试目的,我使用alexTest
/ deJh8detRKw=
),然后点击Test Connection
按钮,应连接到public int TestConnect(string userName, string password)
Web服务方法。
这是按钮点击的处理程序
Private Sub Test_Connection_2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestButton_2.Click
If URL_Field.Text.Trim <> "" Then
' URL string is not empty
Try 'Attempt to connect to Web Services
'TODO: Add the Uri(URL_Field.Text.Trim + function name)
Dim base_uri As New Uri(URL_Field.Text.Trim) 'URL Server
Dim combined_uri As New Uri(URL_Field.Text.Trim + "/TestConnect")
'TODO: Parse the service_uri to make sure it is syntat. correct URL or handle the exception during constr
Dim web_request As HttpWebRequest = WebRequest.Create(combined_uri)
web_request.Method = "POST"
web_request.ContentType = "application/x-www-form-urlencoded"
Dim string_data As String = String.Format("userName={0}&password={1}", userNameBox.Text.Trim(), Uri.EscapeDataString(passBox.Text.Trim()))
Dim byte_data() As Byte = ASCIIEncoding.ASCII.GetBytes(string_data)
web_request.ContentLength = byte_data.Length
'Get Response
Dim web_resp As HttpWebResponse = web_request.GetResponse()
Dim streamReader As New StreamReader(web_resp.GetResponseStream(), Encoding.UTF8)
Dim response_string As String = streamReader.ReadToEnd()
它会跑到Dim web_resp As HttpWebResponse = web_request.GetResponse()
行并停止。我没有例外,没有错误,没有。
Web服务工作,因为我能够通过浏览器测试它。但是,当我运行代码时,不会停止在Web方法上的断点处,即永远不会调用web方法。