不錯的Web Service:C# to VB.NET Code Service
很多人在網路上找一些asp.net的程式碼範例....
會遇到一些問題,就是學VB.net的人..確找到c#的範例....
現在有這個web service真的是大讚了....可以將c# code 轉成 vb.net code
小弟寫個範例介紹如何使用這個web service呀...分享給大家...
web service 來源:http://www.kamalpatel.net/ConvertCSharp2VBService.asmx
這個網址是WSDL Scheme的位址
http://www.kamalpatel.net/ConvertCSharp2VBService.asmx?WSDL
先利用 Visual Studio 2005 命令提示字元 將要呼叫web service的類別下載回來...
將產生的ConvertCSharp2VBService.cs放到App_Code裡...
CSharp2VB.aspx
01 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CSharp2VB.aspx.cs" Inherits="CSharp2VB" %>
02
03 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04 <html xmlns="http://www.w3.org/1999/xhtml">
05 <head id="Head1" runat="server">
06 <title>CSharp2VB</title>
07 </head>
08 <body>
09 <form id="form1" runat="server">
10 <div>
11 C#<br />
12 <asp:TextBox ID="TextBox1" runat="server" Height="150px" TextMode="MultiLine" Width="499px"></asp:TextBox><br />
13 VB<br />
14 <asp:TextBox ID="TextBox2" runat="server" Height="150px" TextMode="MultiLine" Width="500px"></asp:TextBox>
15 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Convert" /></div>
16 </form>
17 </body>
18 </html>
19
02
03 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04 <html xmlns="http://www.w3.org/1999/xhtml">
05 <head id="Head1" runat="server">
06 <title>CSharp2VB</title>
07 </head>
08 <body>
09 <form id="form1" runat="server">
10 <div>
11 C#<br />
12 <asp:TextBox ID="TextBox1" runat="server" Height="150px" TextMode="MultiLine" Width="499px"></asp:TextBox><br />
13 VB<br />
14 <asp:TextBox ID="TextBox2" runat="server" Height="150px" TextMode="MultiLine" Width="500px"></asp:TextBox>
15 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Convert" /></div>
16 </form>
17 </body>
18 </html>
19
CSharp2VB.aspx.cs
01
using System;
02
using System.Data;
03
using System.Configuration;
04
using System.Collections;
05
using System.Web;
06
using System.Web.Security;
07
using System.Web.UI;
08
using System.Web.UI.WebControls;
09
using System.Web.UI.WebControls.WebParts;
10
using System.Web.UI.HtmlControls;
11
12
public partial class CSharp2VB : System.Web.UI.Page
13
{
14
protected void Page_Load(object sender, EventArgs e)
15
{
16
string[] str = { "1", "2" };
17
}
18
protected void Button1_Click(object sender, EventArgs e)
19
{
20
ConvertCSharp2VBService service = new ConvertCSharp2VBService();
21
this.TextBox2.Text = service.Execute(this.TextBox1.Text);
22
}
23
}

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

執行結果: