vb 调用webservice 博客分类: 其他
程序员文章站
2024-03-22 20:22:04
...
Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel Imports System.Net Imports System.IO Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports Newtonsoft.Json.Linq.JArray Imports System.Web ' 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 ' <System.Web.Script.Services.ScriptService()> _ <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _ <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <ToolboxItem(False)> _ Public Class HotInfoWs Inherits System.Web.Services.WebService Private BackendAddress As String = "http://172.17.16.55:8080" Private contentTypeHotDeals As String = "/cms/hotDeals/index.jhtml" Private contentTypeDealsForMembers As String = "/cms/dealsForMembers/index.jhtml" Dim noticeInfo As String = "please check the back network!" Dim strReturn As String = "" Public hh As New Hashtable Private deals = "deals" Private members = "members" ' Public request As System.Net.HttpWebRequest 'Dim request1 As System.Web.HttpRequest <WebMethod()> _ Public Function GetHotDeals() As String Return getMembersServiceContent(contentTypeHotDeals, deals) End Function <WebMethod()> _ Public Function GetDealsForMembers() As String Return getMembersServiceContent(contentTypeDealsForMembers, members) End Function Private Function getMembersServiceContent(ByVal serviceType As String, ByVal functionType As String) Dim sm = Server.MapPath("~/") + "images\" + functionType + "\" Try Dim uri As New Uri(BackendAddress + serviceType) Dim request As HttpWebRequest = WebRequest.Create(uri) request.Method = "Get" request.Timeout = 60000 Dim webrep As WebResponse = request.GetResponse() Dim resStream As Stream = webrep.GetResponseStream() Dim streamReader As New StreamReader(resStream, System.Text.Encoding.UTF8) strReturn = streamReader.ReadToEnd() streamReader.Close() resStream.Close() webrep.Close() Catch exxx As Exception Return noticeInfo End Try Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer Dim product As New ProductInfo ' Dim products As New JavaScriptSerializer ' JsonSerializer.Deserialize(new JsonTextReader(new StringReader(sw.GetStringBuilder().ToString())), typeof(ProductCollection)); Dim dict = serializer.Deserialize(Of List(Of ProductInfo))(strReturn) Dim productNum = dict.Count Try Dim ht As Hashtable = Application(functionType) Dim list As New List(Of ProductInfo) If ht.Keys.Count = productNum Then Dim imgPath = "" For Each entry As DictionaryEntry In ht Dim pro As ProductInfo = entry.Value imgPath = "/images/" + functionType + "/" + Split(pro.imgPath, "/")(6) pro.imgPath = imgPath list.Add(pro) Next Dim str = JavaScriptConvert.SerializeObject(list) Return str Else Dim b() As Byte ' MsgBox(dict.First.title) For Each pro As ProductInfo In dict Dim ss = BackendAddress + pro.imgPath Dim imageName = Split(pro.imgPath, "/")(6) Dim dFile As New System.Net.WebClient Dim name = sm + imageName Try b = dFile.DownloadData(ss) System.IO.File.WriteAllBytes(name, b) pro.imgPath = "images/" + functionType + "/" + imageName ' list1.Add(pro) Catch exx As Exception End Try hh.Add(pro.author, pro) Next Application.Lock() Application(functionType) = hh Application.UnLock() Dim str = JavaScriptConvert.SerializeObject(dict) Return str End If ' MsgBox(ht.Keys.Count) Catch ex As Exception Application(functionType) = hh Dim b() As Byte ' MsgBox(dict.First.title) For Each pro As ProductInfo In dict Dim ss = BackendAddress + pro.imgPath Dim imageName = Split(pro.imgPath, "/")(6) Dim dFile As New System.Net.WebClient Dim name = sm + imageName Try b = dFile.DownloadData(ss) System.IO.File.WriteAllBytes(name, b) pro.imgPath = "images/" + functionType + "/" + imageName ' list1.Add(pro) Catch exx As Exception End Try hh.Add(pro.author, pro) Next Application.Lock() Application(functionType) = hh Application.UnLock() Dim str = JavaScriptConvert.SerializeObject(dict) Return str End Try End Function Public Class ProductInfo Public author As Integer Public id As Integer Public title As String Public txt As String Public imgPath As String Public Property pauthor() As Integer Get Return author End Get Set(ByVal value As Integer) author = value End Set End Property Public Property pid() As Integer Get Return id End Get Set(ByVal value As Integer) id = value End Set End Property Public Property ptitle() As String Get Return title End Get Set(ByVal value As String) title = value End Set End Property Public Property ptxt() As String Get Return txt End Get Set(ByVal value As String) txt = value End Set End Property Public Property pimgPath() As String Get Return imgPath End Get Set(ByVal value As String) imgPath = value End Set End Property End Class End Class
推荐阅读
-
vb 调用webservice 博客分类: 其他
-
java调用js:javax.script 博客分类: javajs javajsjava调用js
-
Java调用oracle存储过程通过游标返回临时表 博客分类: JDBC,存储过程数据库,oracle
-
Java调用oracle存储过程输出自定义对象或二维表 博客分类: JDBC,存储过程数据库,oracle
-
zip版tomcat(6,7)不能注册成windows服务或者注册后不能启动的问题解决 博客分类: Java其他分类微服务数据库
-
记一次“Axis2客户端调用产生大量CLOSE_WAIT连接”的解决过程 博客分类: 原创 axis2webserviceGCclose_wait
-
js调用后台,后台调用前台等方法总结 博客分类: javascript jquery开发
-
ASP嵌套VB代码读取ini配置文件 博客分类: VB ASP .NET VBASPini
-
ASP构造SOAP调用WebService 博客分类: ASP ASPSOAPWEBSERVICE
-
js调用后台,后台调用前台等方法总结 博客分类: javascript jquery开发