+ Start a Discussion

Vb.net to SFDC Integration Error?

Hi All,

  I am connecting VB.Net to SFDC and fetch contact details display it in datagrid view in VB.net application.
While build my application I am getting error.Please help me.

Error:Type 'ApexApi1.SoapClient' is not defined.

This is my code:

Imports SFAPI_2.ApexApi1

Public Class Form1
    Implements IDisposable

    Private Shared sessionId As String = "mysessionid"
    Private Shared serverUrl As String = "https://login.salesforce.com/services/Soap/c/34.0"

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn.Click
        Dim records As ApexApi1.sObject() = getContactDetails()
        If records.Length <= 0 Then
            MsgBox("No records found!")
            Exit Sub
        End If

        ' Convert custom object to dataset to display properly in datagridview
        Dim ds As DataSet = New DataSet
        ds = rowTodsContact(records)

        Dim TableView As DataView
        TableView = ds.Tables("ContData").DefaultView
        DataGridView1.DataSource = TableView
    End Sub

    Private Function getContactDetails() As ApexApi1.sObject()
            Dim lr As ApexApi1.LoginResult

            Using ss As ApexApi1.SoapClient = New ApexApi1.SoapClient

                If sessionId Is Nothing Or sessionId = "" Then
                    ' Login Call
                    lr = ss.login(Nothing, "myusername", "mypassword" & "securitytoken")
                    If lr.passwordExpired Then
                        MsgBox("Password Expired")
                        Exit Function
                    End If
                    sessionId = lr.sessionId.ToString().Trim()
                    serverUrl = lr.serverUrl.ToString().Trim()
                End If
            End Using

            ' Store SessionId in SessionHeader; We will need while making query() call
            Dim sHeader As ApexApi1.SessionHeader = New ApexApi1.SessionHeader
            sHeader.sessionId = sessionId

            ' Variable to store query results
            Dim qr As ApexApi1.QueryResult = New ApexApi1.QueryResult
            Using ss1 As ApexApi1.SoapClient = New ApexApi1.SoapClient
                ss1.ChannelFactory.Endpoint.Address = New System.ServiceModel.EndpointAddress(serverUrl)
                ' Limit to display only 100 records
                ss1.query(sHeader, Nothing, Nothing, Nothing, "SELECT AccountId, OwnerId, FirstName, LastName, Email FROM Contact LIMIT 100", qr)
            End Using

            Dim records As ApexApi1.sObject() = qr.records
            Return records
        Catch ex As Exception

            Return Nothing
        End Try
    End Function
    Private Function rowTodsContact(ByVal records() As ApexApi1.sObject) As DataSet
        Dim ds As DataSet = New DataSet
            ds.Tables("ContData").Columns.Add("AccountId", GetType(String))
            ds.Tables("ContData").Columns.Add("OwnerId", GetType(String))
            ds.Tables("ContData").Columns.Add("FirstName", GetType(String))
            ds.Tables("ContData").Columns.Add("LastName", GetType(String))
            ds.Tables("ContData").Columns.Add("Email", GetType(String))
            For i As Integer = 0 To records.Length - 1
                Dim con As ApexApi1.Contact = DirectCast(records(i), ApexApi1.Contact)
                Dim accId As String = con.AccountId
                Dim ownerId As String = con.OwnerId
                Dim fName As String = con.FirstName
                Dim lName As String = con.LastName
                Dim email As String = con.Email
                ds.Tables("ContData").Rows.Add(accId, ownerId, fName, lName, email)
            Return ds
        Catch ex As Exception

            Return Nothing
        End Try
    End Function

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
End Class

Please guide me .