简体   繁体   English

将Web方法从C#转换为vb.net

[英]Convert a webmethod from c# to vb.net

I did the web method below using C#. 我使用C#执行了以下Web方法。 I'm tryin to convert this into VB.NET, but I'm missing something. 我正在尝试将其转换为VB.NET,但我缺少一些东西。 I'm using it with an ajax calling, from a paginator/sorter table plugin. 我正在通过分页器/排序器表插件将其与ajax调用一起使用。

[WebMethod( EnableSession = true )]
public static object listaPessoas(int jtStartIndex = 0, 
                                  int jtPageSize = 0, 
                                  string jtSorting = null)
{
    return new { Result = "OK", 
                 Records = persons.ToList(), 
                 TotalRecordCount = persons.count };
}

First, error in VB - I can't leave the parameters as optional(" Attribute WebMethod cannot be applied to a method with optional parameters "): 首先,VB中的错误-我无法将参数保留为可选项(“ 属性WebMethod无法应用于具有可选项参数的方法:)

<WebMethod()> _
Public Function listaPessoas(Optional ByVal jtStartIndex As Integer = 0, 
                             Optional ByVal jtPageSize As Integer = 0, 
                             Optional ByVal jtSorting As String = Nothing)

Second, I don't know how to return the message "OK" and the list of people. 其次,我不知道如何返回消息“ OK”和人员列表。

Can anyone me help to convert this into VB.NET? 我可以帮忙将其转换为VB.NET吗?

Seems like you can't use optional parameters with WebMethods. 似乎您不能在WebMethods中使用可选参数。 You can use overloading. 您可以使用重载。 Example: 例:

<WebMethod()> _
Public Function listaPessoas(jtStartIndex As Integer, jtPageSize As Integer)

<WebMethod()> _
Public Function listaPessoas(jtStartIndex As Integer, jtPageSize As Integer, jtSorting As String)

The C# object returned is an anonymous object. 返回的C#对象是一个匿名对象。 The VB syntax is: VB语法为:

Return New With { .Result = "OK", 
                  .Records = persons.ToList(), 
                  .TotalRecordCount = persons.count }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM