data set and web services

jvcoach23

Centurion
Joined
May 22, 2003
Messages
192
Location
Saybrook, IL
I'm trying to learn about web services. I have a data adapter that I'm putting info into through a stored procedure in Sql server. I've tried typing everythign in, I've tried using the drag and drop features but I can't get it to work with a web service. I can get it to work with a windows form though. Hope someone can tell me what I'm doing wrong.

Here is the code....

Visual Basic:
Imports System.Web.Services
Imports System.Data
Imports System.Data.SqlClient



<System.Web.Services.WebService(Namespace:="http://www.addieandreece.us")> _
Public Class Service1
    Inherits System.Web.Services.WebService

#Region " Web Services Designer Generated Code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Web Services Designer.
        InitializeComponent()

        'Add your own initialization code after the InitializeComponent() call

    End Sub

    'Required by the Web Services Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Web Services Designer
    'It can be modified using the Web Services Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents daInvTrxAssortment As System.Data.SqlClient.SqlDataAdapter
    Friend WithEvents spInvTrxAssortmentFetch As System.Data.SqlClient.SqlCommand
    Friend WithEvents cnSql As System.Data.SqlClient.SqlConnection
    Friend WithEvents dsInvTrxAssortment As System.Data.DataSet
    Friend WithEvents spInvTrxAssortmentUpdateShannon As System.Data.SqlClient.SqlCommand
    Friend WithEvents daEmployeeList As System.Data.SqlClient.SqlDataAdapter
    Friend WithEvents dsEmployeeList As System.Data.DataSet
    Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.daInvTrxAssortment = New System.Data.SqlClient.SqlDataAdapter
        Me.spInvTrxAssortmentFetch = New System.Data.SqlClient.SqlCommand
        Me.cnSql = New System.Data.SqlClient.SqlConnection
        Me.dsInvTrxAssortment = New System.Data.DataSet
        Me.spInvTrxAssortmentUpdateShannon = New System.Data.SqlClient.SqlCommand
        Me.daEmployeeList = New System.Data.SqlClient.SqlDataAdapter
        Me.dsEmployeeList = New System.Data.DataSet
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
        CType(Me.dsInvTrxAssortment, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.dsEmployeeList, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'daInvTrxAssortment
        '
        Me.daInvTrxAssortment.SelectCommand = Me.spInvTrxAssortmentFetch
        Me.daInvTrxAssortment.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "spInvTrxAssortmentFetch", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("intTblInvAssortmentId", "intTblInvAssortmentId"), New System.Data.Common.DataColumnMapping("intMaxStockLevel", "intMaxStockLevel"), New System.Data.Common.DataColumnMapping("intNumberOnDisplay", "intNumberOnDisplay"), New System.Data.Common.DataColumnMapping("intMinimumOrder", "intMinimumOrder"), New System.Data.Common.DataColumnMapping("intCurrentQuantity", "intCurrentQuantity"), New System.Data.Common.DataColumnMapping("curStandardCost", "curStandardCost"), New System.Data.Common.DataColumnMapping("intInTrxID", "intInTrxID"), New System.Data.Common.DataColumnMapping("intInQuantity", "intInQuantity"), New System.Data.Common.DataColumnMapping("curInCost", "curInCost")})})
        '
        'spInvTrxAssortmentFetch
        '
        Me.spInvTrxAssortmentFetch.CommandText = "[spInvTrxAssortmentFetch]"
        Me.spInvTrxAssortmentFetch.CommandType = System.Data.CommandType.StoredProcedure
        Me.spInvTrxAssortmentFetch.Connection = Me.cnSql
        Me.spInvTrxAssortmentFetch.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
        Me.spInvTrxAssortmentFetch.Parameters.Add(New System.Data.SqlClient.SqlParameter("@intTblInvItemID", System.Data.SqlDbType.Int, 4))
        Me.spInvTrxAssortmentFetch.Parameters.Add(New System.Data.SqlClient.SqlParameter("@intTblLocationID", System.Data.SqlDbType.Int, 4))
        '
        'cnSql
        '
        Me.cnSql.ConnectionString = "workstation id=S011038HOME;packet size=4096;user id=sa;data source=""(local)"";pers" & _
        "ist security info=False;initial catalog=PosV1;password=sidskip1"
        '
        'dsInvTrxAssortment
        '
        Me.dsInvTrxAssortment.DataSetName = "NewDataSet"
        Me.dsInvTrxAssortment.Locale = New System.Globalization.CultureInfo("en-US")
        '
        'spInvTrxAssortmentUpdateShannon
        '
        Me.spInvTrxAssortmentUpdateShannon.CommandText = "dbo.[spInvTrxAssortmentUpdateShannon]"
        Me.spInvTrxAssortmentUpdateShannon.CommandType = System.Data.CommandType.StoredProcedure
        Me.spInvTrxAssortmentUpdateShannon.Connection = Me.cnSql
        Me.spInvTrxAssortmentUpdateShannon.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
        Me.spInvTrxAssortmentUpdateShannon.Parameters.Add(New System.Data.SqlClient.SqlParameter("@intTblInvAssortmentId", System.Data.SqlDbType.Int, 4))
        Me.spInvTrxAssortmentUpdateShannon.Parameters.Add(New System.Data.SqlClient.SqlParameter("@intMaxStockLevel", System.Data.SqlDbType.Int, 4))
        Me.spInvTrxAssortmentUpdateShannon.Parameters.Add(New System.Data.SqlClient.SqlParameter("@intNumberOnDisplay", System.Data.SqlDbType.Int, 4))
        '
        'daEmployeeList
        '
        Me.daEmployeeList.SelectCommand = Me.SqlSelectCommand1
        Me.daEmployeeList.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "spAEmployeeList", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("intTblEmployeeId", "intTblEmployeeId"), New System.Data.Common.DataColumnMapping("vcFirstName", "vcFirstName"), New System.Data.Common.DataColumnMapping("vcLastName", "vcLastName")})})
        '
        'dsEmployeeList
        '
        Me.dsEmployeeList.DataSetName = "NewDataSet"
        Me.dsEmployeeList.Locale = New System.Globalization.CultureInfo("en-US")
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "[spAEmployeeList]"
        Me.SqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure
        Me.SqlSelectCommand1.Connection = Me.cnSql
        Me.SqlSelectCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
        CType(Me.dsInvTrxAssortment, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.dsEmployeeList, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        'CODEGEN: This procedure is required by the Web Services Designer
        'Do not modify it using the code editor.
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

#End Region

    ' WEB SERVICE EXAMPLE
    ' The HelloWorld() example service returns the string Hello World.
    ' To build, uncomment the following lines then save and build the project.
    ' To test this web service, ensure that the .asmx file is the start page
    ' and press F5.
    '
    <WebMethod()> Function GetEmployeeList()
        Me.daEmployeeList.Fill(Me.dsEmployeeList)
        Return Me.dsEmployeeList
    End Function

    <WebMethod()> Function GetEmployeeListMan()
        Dim daEmployeeListMan As SqlDataAdapter = New SqlDataAdapter
        Dim dsEmployeeListMan As DataSet = New DataSet

        daEmployeeListMan.SelectCommand = New SqlCommand
        daEmployeeListMan.SelectCommand.CommandText = "spAEmployeeList"
        daEmployeeListMan.SelectCommand.CommandType = CommandType.StoredProcedure
        daEmployeeListMan.SelectCommand.Connection = cnSql

        daEmployeeListMan.Fill(dsEmployeeListMan, "EmployeeListMan")
        Return dsEmployeeListMan
    End Function

The error I'm getting when i try to run the dataservice is as follows.. this isn't through the client, it's when your working with the service part.

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Data.DataSet may not be used in this context. To use System.Data.DataSet as a parameter, return type, or member of a class or struct, the parameter, return type, or member must be declared as type System.Data.DataSet (it can't be object). Objects of type System.Data.DataSet may not be used in un-typed collections, such as ArrayLists.
at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
at
I've been trying to work my way through it but am not getting it. Hopefully someone can help
thanks
shannon
 
Try specifying your return types:

Code:
 <WebMethod()> Function GetEmployeeList() as System.Data.DataSet
        Me.daEmployeeList.Fill(Me.dsEmployeeList)
        Return Me.dsEmployeeList
    End Function
 
Back
Top