我需要在vb.NET中创建一个具有用户名和密码的Web服务 换句话说,我需要我的网络服务有像Windows帐户的凭证。
但我不知道怎么能这样做......
答案 0 :(得分:0)
创建Web服务时,只需添加用户名和密码的参数即可。例如,以下webservice将用户名和密码作为字符串,使用它们登录到数据库并返回数据集(未显示打开的连接函数)。我使用TLS 1.2加密连接:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports Oracle.DataAccess.Client
Imports System.ComponentModel
Imports System.Net.mail
Imports System.IO
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class MyWebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetData(ByVal pUsername As String, ByVal pPassword As String) As DataSet
Dim MyDataSet As DataSet
Dim MyConnection As OracleConnection = OpenConnection(pUsername, pPassword)
Try
MyDataSet = GetUserData(MyConnection, pUsername)
MyConnection.Close()
MyConnection.Dispose()
MyConnection = Nothing
Return MyDataSet
Catch ex As Exception
MyConnection.Close()
MyConnection.Dispose()
MyConnection = Nothing
Return New DataSet
End Try
End Function
End Class