Binding Control to Webservice - InfoPath Dev
in

InfoPath Dev

Binding Control to Webservice

Last post 07-30-2007 10:03 AM by JamesLaker. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-30-2007 07:44 AM

    Binding Control to Webservice

    Hi,

    I as wondering if anyone could tell me how I could bind a control to a Webservice. Below is how I fetch the data making use of a SQL Data Connetion, and I'm exploring working with Webservices.

            Public Sub fillAwardsCombo(ByVal strAlias As String)
                Try
                    'Instantiate a variable to access the specified data source
                    ' from the DataSourceCollection of the form.
                    Dim myADOConnection As AdoQueryConnection = DirectCast(Me.DataConnections("Awards"), AdoQueryConnection)
                    myADOConnection.Command = " SELECT A.AwardID,A.AwardName FROM Judge J " & _
                                                 "INNER JOIN JudgeLink JL ON JL.JudgeID = J.JudgeId " & _
                                                 "INNER JOIN Awards A On JL.AwardId = A.AwardId " & _
                                                 "WHERE Alias = '" & strAlias & "'"

                    myADOConnection.Execute()
                    myADOConnection = Nothing
                Catch ex As Exception

                End Try

            End Sub

     So what I would like to know is how I woul change the code to query a Webservice. Also what the Webservice should return, but I'm guessing it will return a dataset. Is this correct?

    Kind regards

       James Laker

  • 07-30-2007 10:03 AM In reply to

    Re: Binding Control to Webservice

    Managed to get it working. To requery a webservice:

                Try
                    'Instantiate a variable to access the specified data source
                    ' from the DataSourceCollection of the form.

                    Dim rootNavigator As XPathNavigator = Me.DataSources("getAwardsWS").CreateNavigator()
                    Dim myAlias As XPathNavigator = rootNavigator.SelectSingleNode("/dfs:myFields/dfs:queryFields/tns:getAwards/tns:strAlias", Me.NamespaceManager)
                    myAlias.SetValue(strAlias)

                    Dim myWebservice As WebServiceConnection = DirectCast(Me.DataConnections("getAwardsWS"), WebServiceConnection)

                    myWebservice.Execute()
                    myWebservice = Nothing

                Catch ex As Exception

                End Try


    getAwardsWS is a Data Connection from Webservice where the code looks like this:

        <WebMethod()> _
        Public Function getAwards(ByVal strAlias As String) As DataTable

            Dim ds As New DataSet
            Dim sqlcn As New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)
            Dim da As New SqlDataAdapter("", sqlcn)

            da.SelectCommand.CommandText = "SELECT A.AwardID,A.AwardName FROM Judge J " & _
                                                 "INNER JOIN JudgeLink JL ON JL.JudgeID = J.JudgeId " & _
                                                 "INNER JOIN Awards A On JL.AwardId = A.AwardId " & _
                                                 "WHERE Alias = '" & strAlias & "'"

            da.Fill(ds)

            Return ds.Tables(0)

        End Function

     

    Hope it'll help someone in the future...

     

     

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.