`
qinya06
  • 浏览: 595067 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

vb 调用webservice

 
阅读更多
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

    在探讨“VB如何调用WebService”的主题时,我们首先需要理解几个关键概念:Visual Basic(简称VB),WebService,以及SOAP协议。Visual Basic是一种由微软开发的面向对象的编程语言,广泛应用于Windows平台上的应用...

    vb6.0调用webservice详解

    在VB6.0中调用Web服务,特别是WebService,是一个重要的技术点,它允许传统的VB6应用程序利用基于网络的服务来扩展其功能。由于VB.NET的普及,很多开发者更倾向于使用.NET框架,但考虑到VB6的广泛使用和某些特定场景...

    VB6调用WebService

    在提供的【VB调用WebService源码】中,你可以找到具体的实现示例,通过学习和研究这些代码,你可以更好地理解和掌握VB6调用WebService的技巧。实践中,你可以根据自己的需求修改和扩展这些源码,以适应不同的...

    VB.NET做的调用WebService的小程序

    【VB.NET调用WebService的基本概念】 VB.NET(Visual Basic .NET)是微软开发的一种面向对象的编程语言,它是.NET框架的一部分,支持多种编程模式,包括面向对象编程。WebService是一种基于HTTP协议的Web应用程序,...

    VB.NET/JAVA 采用SOAP 与Webservice发送/接收数据

    ### VB.NET与Java通过SOAP协议访问WebService的知识点 #### 一、基础知识介绍 - **SOAP (Simple Object Access Protocol)**: 是一种轻量级协议,用于交换结构化的信息。它定义了用于构造消息以及进行信息传输的...

    在WinForm程序中调用WebService

    在WinForm应用程序中调用WebService是一项常见的任务,它允许客户端应用程序与远程服务器上的服务进行交互,从而实现数据交换和功能扩展。以下是如何在WinForm中实现这一操作的详细步骤及涉及的相关知识点: 1. **...

    SQL Server调用Webservice示例

    在示例中,"SQL项目调用Webservice示例"可能包含了一个完整的.NET存储过程示例,用于演示如何构建和调用Web Service。可能的结构包括: - 存储过程源代码,展示如何使用`System.Web.Services`命名空间的`WebClient`...

    VB6调用webservice所需的插件

    在VB6(Visual Basic 6)环境中调用Web服务,通常需要特定的组件或插件来实现,因为VB6本身并不直接支持SOAP协议,这是Web服务最常用的通信标准。本资源包含两个关键文件:setup.exe和soapsdk.exe,它们可能是用于在...

    PB6,PB7,PB8,PB9,PB10,PB11调用WEBSERVICE,并解决超时问题

    “调用WEBSERVICE”是指在PowerBuilder应用中使用Web服务。Web服务是一种基于开放标准(如SOAP、WSDL和UDDI)的软件组件,允许不同系统间的互操作性。在PowerBuilder中,可以通过创建Web引用或者数据窗口对象来调用...

    webservices VB接口

    1. 客户端使用VB调用Web服务时,需要引用Web服务的WSDL文件。VB.NET会自动生成一个代理类,该类提供了与Web服务接口相对应的方法。 2. 调用Web服务接口:在VB代码中实例化这个代理类,然后调用对应的方法,传入必要...

    VB.net webservice包括服务端及客户端程序

    在VB.NET中,这些接口通常表现为Public Sub或Public Function,它们需要添加WebMethod特性以指示其可被Web服务调用。例如: ```vbnet Imports System.Web.Services &lt;WebService(Namespace:="http://example.com/")...

    调用webservice工具

    标题中的“调用WebService工具”指的是用于与Web服务交互的应用程序。在软件开发中,Web服务是一种通过HTTP协议提供功能的远程调用技术,它允许不同的应用程序之间进行数据交换和协同工作。在这种情况下,提到的是一...

    vb.net webservice 源程序

    首先,VB.NET Web服务(ASMX)是基于SOAP(Simple Object Access Protocol)协议的,它允许开发者创建可跨平台、跨语言的远程调用服务。SOAP是一种XML消息协议,用于在应用程序之间交换结构化和类型化的信息。 创建...

Global site tag (gtag.js) - Google Analytics