INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: How to make Web Service for a VB.net plugin  (Read 2768 times)

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
How to make Web Service for a VB.net plugin
« on: May 04, 2007, 05:15:52 am »

Hello

I'm trying to make a web service to forward SQL queries from a VB.net plugin to my SQL server and return the result, but have little idea of how to attack this. Have been searching the web and have made something that look like it can work as a web service:

The simple WebService.asmx file:

Code: [Select]
<%@ WebService Language="VB" Class="MoodAndStyle" %>

Imports System.Web.Services
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class MoodAndStyle
  Private Function GetDataSet(SQLQuery as String) as DataSet
    '1. Create a connection
    Dim SQLconn as New SqlConnection("Data Source=10.0.0.5;Initial Catalog=Mood;User Id=moodDBUser;Password=test;")

    '2. Create the command object, passing in the SQL string
    Dim command as New SqlCommand(SQLQuery, SQLconn)

    SQLconn.Open()

    '3. Create the DataAdapter
    Dim dataAdapter as New SqlDataAdapter()
    dataAdapter.SelectCommand = command


    '4. Populate the DataSet and close the connection
    Dim myDataSet as New DataSet()
    dataAdapter.Fill(myDataSet)
    SQLconn.Close()

    'Return the DataSet
    Return myDataSet
  End Function

  <WebMethod()> Public Function GetArtists() as DataSet
    Return GetDataSet("SELECT * FROM Artist")
  End Function
End Class

Anyone know what code I need in my VB.net pluging? For starters I would just want a button to get the dataSet.
I have also read about a web service proxy, but if this get's any more complicated than it have to be, I think I'll give up.
Any suggestions would be great!

- Carl
Logged
- I may not always believe what I'm saying

PaulSinnema

  • Galactic Citizen
  • ****
  • Posts: 393
  • You don't know what you're missing until its gone
Re: How to make Web Service for a VB.net plugin
« Reply #1 on: May 06, 2007, 07:29:37 am »

MrHaugen,

Like I said, I don't have much experience in this field. The Visual Studio Professional 2005 IDE has a template that creates a 'Hello World' Webservice for me. I've done that and this is the code it produces (file called Service1.asmx.vb).

Code: [Select]
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
       Return "Hello World"
    End Function

End Class

It also creates a Web.config file that looks like this:

Code: [Select]
<?xml version="1.0"?>

<configuration>
 
    <appSettings/>
    <connectionStrings/>
 
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.

            Visual Basic options:
            Set strict="true" to disallow all data type conversions
            where data loss can occur.
            Set explicit="true" to force declaration of all variables.
        -->
        <compilation debug="true" strict="false" explicit="true" />
        <pages>
            <namespaces>
                <clear />
                <add namespace="System" />
                <add namespace="System.Collections" />
                <add namespace="System.Collections.Specialized" />
                <add namespace="System.Configuration" />
                <add namespace="System.Text" />
                <add namespace="System.Text.RegularExpressions" />
                <add namespace="System.Web" />
                <add namespace="System.Web.Caching" />
                <add namespace="System.Web.SessionState" />
                <add namespace="System.Web.Security" />
                <add namespace="System.Web.Profile" />
                <add namespace="System.Web.UI" />
                <add namespace="System.Web.UI.WebControls" />
                <add namespace="System.Web.UI.WebControls.WebParts" />
                <add namespace="System.Web.UI.HtmlControls" />
            </namespaces>
        </pages>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows" />
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>

I've saved the Project and put it in .rar file for you. You can download it here: http://www.paulsinnema.net/downloads/VBWebService.rar.

My guess is that you can find more information on the MSDN Forums http://forums.microsoft.com/.

Good luck!

Paul.



Logged

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774
Re: How to make Web Service for a VB.net plugin
« Reply #2 on: May 07, 2007, 09:51:38 am »

Thanks. I actually managed this my self 2 days ago. With the good help from the guys on the MSDN forums.
Only thing that remains is to create some methods in the WS and call them from the plugin. I'll have it done in a few days I hope
Logged
- I may not always believe what I'm saying
Pages: [1]   Go Up