namespace AdvaniaUtvService {
// Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
// NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
// a single instance of the service to process all calls.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
[JSONPSupportBehavior]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class DebugService
{ // TODO: Implement the collection resource that will contain the SampleItem instances
[WebGet(UriTemplate = "list/{db},{nokkel}")]
public List<DebugLinje> HentDebugLinjer(string db, string nokkel)
{
List<DebugLinje> liste = new List<DebugLinje>() { new DebugLinje() {DatoTid = DateTime.Now.ToString(), LinjeRef = 1111, Nokkel = "Test", Pakke = "Sys_Pakke", Tekst = "Her er det noe tekst"},
new DebugLinje() {DatoTid = DateTime.Now.ToString(), LinjeRef = 1112, Nokkel = "Test", Pakke = "Sys_Pakke", Tekst = "Her er enda mere tekst"},
new DebugLinje() {DatoTid = DateTime.Now.ToString(), LinjeRef = 1113, Nokkel = "Test2", Pakke = "Sys_Pakke2", Tekst = "Dette er test2"}
};
var utvalg = from linje in liste
where linje.Nokkel.ToLower() == nokkel.ToLower()
select linje;
List<DebugLinje> retur = new List<DebugLinje>();
foreach(DebugLinje linje in utvalg) {
retur.Add(linje);
}
return retur;
}
[WebGet(UriTemplate = "detalj/{db},{gruppeRef}")]
public DebugDetalj HentDebugDetalj(string db, string gruppeRef)
{
DebugDetalj retur = new DebugDetalj(db, gruppeRef);
return retur;
}
[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
// TODO: Add the new instance of SampleItem to the collection
throw new NotImplementedException();
}
[WebGet(UriTemplate = "{id}")]
public SampleItem Get(string id)
{
// TODO: Return the instance of SampleItem with the given id
throw new NotImplementedException();
}
[WebInvoke(UriTemplate = "{id}", Method = "PUT")]
public SampleItem Update(string id, SampleItem instance)
{
// TODO: Update the given instance of SampleItem in the collection
throw new NotImplementedException();
}
[WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
public void Delete(string id)
{
// TODO: Remove the instance of SampleItem with the given id from the collection
throw new NotImplementedException();
}
} }
Then I create a simple html page with a button which calls this JavaScript code:
function VisListe() { var requestUri = http://localhost:56733/Debug.svc/list/db,test?$format=json&callback=?;
// execute AJAX request
$.getJSON(requestUri, function (data) { $("#logg").empty(); $("<h2>").html("Logger").appendTo("#logg"); $.each(data, function () { $("#logg").append("<p>" + data.LinjeRef + ", " + data.Nokkel + ", " + data.Pakke + ", " + data.Tekst + "</p>"); });
});
}
When I use Fiddler, I can see the web service returns the expected result, but nothing happens.
The code in the function(data) block is not executed.
Does anyone knows what's wrong?
Thanks.