如何在Webservice VB.NET中将数组作为函数参数传递? [英] How to pass Array as Function Parameter in Webservice VB.NET?

查看:95
本文介绍了如何在Webservice VB.NET中将数组作为函数参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

又是我.
我想问< u>如何在函数中使用(传递和返回)数组?</u>
我的Webservice项目中有此代码

Hi, its me again.
I wanted to ask on <u>How to use (pass and return) array in function?</u>
I have this code on my Webservice project

WebMethod() _
      Public Function InsertProduk(ByVal key As Array, ByVal val As String, ByVal konter As Integer) As DataSet
        Dim conn As String
        Dim i As Integer = konter
        For a As Integer = 0 To i
            conn = &quot;server=localhost;uid=root;pwd=;database=miles&quot;
            Dim sql As String = &quot;insert into trade set id_pro="'' + key(i) + ''";
            Dim konek As New MySqlConnection(conn)
            Dim OdbcDa As New MySqlDataAdapter(Sql, conn)
            konek.Open()
            Dim ds As New DataSet
            OdbcDa.Fill(ds)
            konek.Close()
            Return ds
        Next
    End Function


这就是我在Web服务中导入的内容


This is what I imports in my webservice

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports MySql.Web
Imports MySql.Web.SessionState


但是当我尝试浏览它时,系统抛出此错误:
您必须在System.Array上实现默认访问器,因为它继承自ICollection.


But when I tr=ied to browse it, system throws me this error :
You must implement a default accessor on System.Array because it inherits from ICollection.

推荐答案

您的错误与对象类型有关您正在传递到您的Web服务. VB.NET在传递给它的内容上非常特别.我会看这篇文章

您必须在System.Array b上实现默认访问器... [
Your error is to do with the type of object that you are passing to your webservice. VB.NET is rather particular in what you can pass to it. I would have a look at this article

You must implement a default accessor on System.Array b...[^]

It would appear that you need to change the array to a generic list, there is an example of this in the article. Also to return a true dataset you will need to change

Return ds



,因为上面将返回
Diffgram [ ^ ]



to, as the above will return a Diffgram[^]

return ctype(ds, dataset)


这篇关于如何在Webservice VB.NET中将数组作为函数参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆