c# mysql

Aug 31 2005 5:11 AM
Hi

I am very very new to c# , more used to PHP. I am trying to do a simple thing which is basically connect to mysql and pull back the data as a webservice.

Intially i got the error below , which seemed to me to be something to do with inheritance of classes or something

Initial error:

Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. [ i havent pasted the rest of the error]


My intial code was:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using MySql.Data.MySqlClient;


namespace test2
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
private string HName;
private decimal HRef;

//public Service1()
// {
//CODEGEN: This call is required by the ASP.NET Web Services Designer
// InitializeComponent();
// }

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the project
// To test this web service, press F5

[WebMethod (Description="Get ref")]
public Service1 GetRef()
{
Service1 htl = new Service1();

//Service1 hotel = new Service1();
//DB Connection
MySqlConnection conn = new MySqlConnection("Server=xxxxxxx;Uid=xxxxxxx;Pwd=xxxx;Database=xxxxx");



try
{
conn.Open();
}
catch(MySqlException m)
{
throw new Exception("Could Not Connect To Database" + m);
}

MySqlCommand comm = new MySqlCommand("SELECT ref,name FROM detail WHERE ref in (3,4,5)", conn);

try
{
MySqlDataReader inverseReader = comm.ExecuteReader();
while(inverseReader.Read())
{

htl.HRef = inverseReader.GetDecimal(0);
htl.HName = inverseReader.GetString(1);
inverseReader.NextResult();
//return htl;
}


return htl;
}
catch(MySqlException m)
{
throw new Exception("Could Not Execute Query. " + m);
}

}

}
}


-------------------------------------------------------------------------------------------------

Somone told me to comment part of the line

public class Service1 //: System.Web.Services.WebService
{
---------
}

so basically there was no call to the webservice class, this stopped the error but now the XML produced is empty and looks like below:

<?xml version="1.0" encoding="utf-8" ?>
<Service1 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/" />

I am not sure how to solve either of these scenarios..

Any help will be good...

Thanks