Source CodeService Description: Sample Implementation: CS2VB_WinFormsConsumer.zipVB6 Sample Implementation: CS2VB_VB6Consumer.zipASP .Net Online Implementation: UsedC#, ASP .Net, VB6, SOAP Toolkit 2.0Article DescriptionThe title says it all. ConvertCSharp2VB is a Web Service that converts a C# code block into VB.Net. It exposes the Service Description and WSDL for the Web Service, so you can implement this functionality in your applications. In this article I will begin by explaining how we can create a Web Service Consumer using C# to access the ConvertCSharp2VB Web Service. Later on I also demonstrate writing a Consumer that accesses this service using VB6 and SOAP Toolkit 2.0.BackgroundConvertCSharp2VB is small utility class developed using C#. The class exposes only one public method, Execute() that receives a C# code block as a parameter and returns its equivalent VB.Net code block. When the Execute() method is called, the class looks for specific patterns in the C# code block and converts each code block to its VB.Net equivalent. The Web Service ConvertCSharp2VBService is simply a wrapper around an instance of this class.The converter currently handles most of the conversions from C# to a VB.Net. It handles namespaces, classes, structs, enums, methods, properties, fields, declaration, for-loops, do-while, while-do, foreach, if-else-end if, select-case, try-catch-finally etc. to name a few. Creating a Consumer in .NetTo access the web service from your project, right click on the project in Solution Explorer and select Add Web References. Type the following URL and select Add Reference. This will add the web reference to your project and create all the necessary plumbing code to access this Web Service. Once the service is added to your project, you can access it just like any other class reference. Here is the code that is required to access this service. private void cmdConvert_Click(object sender, System.EventArgs e){//Instantiate the servicenet.kamalpatel. oService;oService = new net.kamalpatel.;//Call the execute method and handle the formattingstring lcStr = o.Execute(this.txtCSharp.Text);this.txtVB.Text = lcStr.Replace("\n", "\r\n");} Just like any other object we create an instance of the web service class (net.kamalpatel.) and call its methods. In our case we call the Execute() method that receives a CSharp code block and returns a VB.Net code block. Here is an image that shows the implementation of this Web Service developed using ASP.Net.Consumer in VB6Here is a typical code for consuming a Web Service from VB6. We begin by instantiating the SOAP Client and initialize it by specifying the location of our WSDL. Once the SOAP client is initialized, it allows us to call methods of our component as if it were a part if the SOAP Client object. In this case notice that Execute() is actually a method of the Web Service. Private Sub cmdConvert_Click()'Create the SOAP ClientDim soapClientsoapClient = CreateObject("MSSOAP.SoapClient")'Initialize the soap client and pass the URL for'the WSDL file as a parameterDim cWSDL As StringcWSDL = soapClient.mssoapinit(cWSDL)'Call the Execute() method and display the resultsDim cRetVal As StringcRetVal = soapClient.Execute(Me.txtCSharp.Text)Me.txtVB.Text = Replace(cRetVal, vbLf, vbCrLf)End SubInternally, the soap client determines the method and makes the call to the actual service. The last line in the above code block replaces all the line feeds with carriage returns + line feeds. This makes it more readable when displayed in the textbox. ConclusionThe converter does a great job for VB developers as most of the .Net code is still in C#. Even though not 100% complete, it supports 90% of the available types.This Web Service is free to use and access, so if you wish to create consumers on your web site that access this service, it will all yours. If you simply wish to use the service, you can access it from.
©2016
C# Corner. All contents are copyright of their authors.