Jeg vil gerne have fjernet <?xml version="1.0" encoding="utf-8" ?> <string> </string>
udpluk af kode: public string Serialize(Object o) { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); string serializedString = jsSerializer.Serialize(o); return serializedString; } input o er både objekter og lister af min klasse project.
[WebMethod] public string FindProjectByID(string searchString)
using System; using System.ServiceModel; using System.ServiceModel.Web;
namespace E { public class Foobar { public int IV { get; set; } public string SV { get; set; } public double XV { get; set; } } [ServiceContract] public interface IFoobarService { [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "FoobarResource/{n}")] Foobar GiveMe(string n); } public class FoobarService : IFoobarService { public Foobar GiveMe(string n) { return new Foobar { IV=int.Parse(n), SV="Bla bla", XV=double.Parse(n)}; } } }
Service 'WcfServicetest.Service1' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Data.SqlClient; using System.Web.Script.Serialization; using System.Configuration;
namespace WcfServicetest { public class Project { public string projectID { get; set; } public string city { get; set; } public string postal { get; set; } public string address { get; set; } public string picturePath { get; set; } public string pdfPath { get; set; } }
[ServiceContract] public interface IProjectService { [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "ProjectServiceResource1")] string GetAllProjects(int pageSize, int pageNumber);
[OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "ProjectServiceResource2")] string FindProjectsBySearchString(string searchString, int pageNumber, int pageSize);
public class ProjectService : IProjectService { public string GetAllProjects(int pageSize, int pageNumber) { -- code omitted result = Convert.ToString(plist.Count()); result += ","; result += Serialize(plist); return result; }
public string Serialize(Object o) { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); string serializedString = jsSerializer.Serialize(o); return serializedString; }
public string FindProjectsBySearchString(string searchString, int pageNumber, int pageSize) { }
public string FindProjectByID(string searchString) { } } }
using System; using System.Web; using System.Web.Script.Serialization;
namespace E { public class Foobar { public int IV { get; set; } public string SV { get; set; } public double XV { get; set; } } public class FoobarHandler : IHttpHandler { private JavaScriptSerializer ser = new JavaScriptSerializer(); public void ProcessRequest (HttpContext ctx) { ctx.Response.ContentType = "text/plain"; string n = ctx.Request.QueryString["n"]; ctx.Response.Write(ser.Serialize(new Foobar { IV=int.Parse(n), SV="Bla bla", XV=double.Parse(n)})); } public bool IsReusable { get { return true; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Data.SqlClient; using System.Web.Script.Serialization; using System.Configuration;
namespace WcfServicetest { public class Project { public string projectID { get; set; } public string city { get; set; } public string postal { get; set; } public string address { get; set; } public string picturePath { get; set; } public string pdfPath { get; set; } }
A namespace cannot directly contain members such as fields or methods.
Den fulde GetAllProjects metode ser sådan ud:
public string GetAllProjects(string pageSize, string pageNumber) { string result = "0"; int size = Convert.ToInt32(pageSize); int number = Convert.ToInt32(pageNumber);
SqlCommand command = new SqlCommand(); command.Connection = Connection(); command.Connection.Open();
int id = 0;
if (number > 1) { int topNumber = (number - 1) * size; string queryid = "select top 1 ID from project where ID in (select top " + topNumber + " ID from project order by ID asc) order by ID desc"; command.CommandText = queryid; SqlDataReader reader = command.ExecuteReader();
while (reader.Read()) { id = reader.GetInt32(0); } reader.Close(); } command.Parameters.Clear(); command.CommandText = "";
if (size > 1) { command.CommandText = "select top " + pageSize + " Name from project where ID > " + id + " order by ID"; } else { command.CommandText = "select top " + pageSize + " Name from project order by ID"; }
1) Filen skal hedde service1.svc ikke service1.scv.cs 2) Ihvertfald til test bør du ligge den i roden af web app 3) Og der skulle være et servicehost tag i linie 1
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.