okay jeg burde måske have testet det der, det var egentlig kun et eksempel, det lader dog til at virke...
Det andet kode hvor jeg har problemet er lidt langt, så jeg ved ik om jeg bør skrive det her, jeg kan da lige prøve, så må folk læse det hvis de gider :)
dAccess.asmx
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebServices
{
/// <summary>
/// Summary description for dAccess.
/// </summary>
[WebService(Namespace="
http://www.mouse-one.dk/webservices/")]
public class dAccess : System.Web.Services.WebService
{
public dAccess()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
[WebMethod()]
public VareKategori[] GetCat()
{
VareKategori[] cat = new VareKategori[2];
cat[0] = new VareKategori(1, "Grafikkort");
cat[0].AddProducent(new VareProducent(1, "ASUS"));
cat[0].AddProducent(new VareProducent(2, "MSI"));
cat[1] = new VareKategori(2, "Bundkort");
cat[1].AddProducent(new VareProducent(2, "MSI"));
cat[1].AddProducent(new VareProducent(3, "BLA"));
foreach(VareKategori c in cat)
{
Debug.WriteLine("Kategori: " + c.ID + " - " + c.Titel);
foreach(VareProducent p in c.Producenter)
{
Debug.WriteLine("Producent: " + p.ID + " - " + p.Titel);
}
}
return cat;
}
#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
}
}
VareKategori.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebServices
{
/// <summary>
/// Summary description for dAccess.
/// </summary>
[WebService(Namespace="
http://www.mouse-one.dk/webservices/")]
public class dAccess : System.Web.Services.WebService
{
public dAccess()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
[WebMethod()]
public VareKategori[] GetCat()
{
VareKategori[] cat = new VareKategori[2];
cat[0] = new VareKategori(1, "Grafikkort");
cat[0].AddProducent(new VareProducent(1, "ASUS"));
cat[0].AddProducent(new VareProducent(2, "MSI"));
cat[1] = new VareKategori(2, "Bundkort");
cat[1].AddProducent(new VareProducent(2, "MSI"));
cat[1].AddProducent(new VareProducent(3, "BLA"));
foreach(VareKategori c in cat)
{
Debug.WriteLine("Kategori: " + c.ID + " - " + c.Titel);
foreach(VareProducent p in c.Producenter)
{
Debug.WriteLine("Producent: " + p.ID + " - " + p.Titel);
}
}
return cat;
}
#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
}
}
VareProducent.cs
using System;
using System.Diagnostics;
namespace WebServices
{
/// <summary>
/// En vare producent.
/// </summary>
public class VareProducent
{
private int pID;
private string pTitel;
#region Properties
public int ID
{
get
{
return pID;
}
set
{
pID = value;
}
}
public string Titel
{
get
{
return pTitel;
}
set
{
pTitel = value;
}
}
#endregion
#region Constructors
/// <summary>
/// Opret producent.
/// </summary>
public VareProducent()
{
Debug.WriteLine("New VareProducent()");
}
/// <summary>
/// Opret producent og tildel ID, samt Titel.
/// </summary>
/// <param name="id">Producentens ID.</param>
/// <param name="titel">Producentens Titel.</param>
public VareProducent(int id, string titel)
{
pID = id;
pTitel = titel;
Debug.WriteLine("New VareProducent(" + id + ", " + titel + ")");
}
#endregion
}
}
Værsgo og find fejlen eller test det eller whatever you want, den returner ihvertfald ikke hvad den burde.