AJAX :: Wcf Based Web Service Returns Data In JSON?

Jul 7, 2010

I want to make a web servcie(.svc) that returns JSON data after entering the input.....which is resulted as in the downloaded filein JSON format.i want something like that-http://209.62.6.226/GracoRest/service.svc/Rest/WheretoBuyplease help me for the above but....step by step...i m trying WCF very 1st time

View 3 Replies


Similar Messages:

WCF / ASMX :: Calling A Remote Or Local Web Service That Returns A JSON With JQuery?

Mar 16, 2011

how to create a Web service that returns a JSON(or JSONP). That also should be able to work for cross-domain access aswell as for a local call.. help to get this working or for a few links for further reading about this

View 2 Replies

Crystal Reports :: Create A Web Service That Returns Output In JSON Format

Mar 29, 2013

How can we consume a web service using asp.net out put in json formate?

View 1 Replies

Making A Call To A Page That Returns JSON Using AJAX

Feb 9, 2010

I have a Page that expects a POST Request and returns some JSON. Essentially it's an .ashx Page, but that doesn't really matter.

When using jQuery, I would use jQuery.Post with "json" as dataType to simply make the POST request and get an object back. However, for the current project I mainly use ASP.net AJAX and I don't want to add jQuery just for the call.

For ASP.net AJAX, I only found information on how to call a "traditional" web service though, which means adding a asp:ServiceReference to the ScriptManager and having a "real" Web Service at the end.

Is there a simpler way to make a POST call to a Page? I could live with getting the raw JSON and then manually eval()ing it, but I don't want to create a full asmx web service (deploying them on SharePoint is a bit painful, and my ashx handler works fine)

View 3 Replies

AJAX :: Unable To Make Wcf JSON Ajax Service Work Through Http Like Asmx?

Jun 22, 2010

I am new to WCF, I was using web service asmx before. I have trouble on making my wcf JSON ajax service work through http like asmx.Could you help me see what wrong in my code?My WCF services are defined in my website application folder. My aim is to call this service in my aspx page java-script code and return complex object back as JSON to my javascript. I have no problem on doing this through classic asmx web service.


When I try to test it through my browser by type this in the URL , URL-http://localhost:3849/WebServices/Account/WCFCompanyService.svc/GetAll. it return "Method not allowed."

But if I type just this URL-http://localhost:3849/WebServices/Account/WCFCompanyService.svc, it return this:

WCFCompanyService Service

You have created a service.To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe URL-http://localhost:3849/WebServices/Account/WCFCompanyService.svc?wsdl

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:

C#

class Test { static void Main() { HelloClient client = new HelloClient();

[Code]....

This is my Ajax-enabled WCF service code:

[Code]....

This is the web.config service model setting

[Code]....

View 1 Replies

AJAX :: Unable To Use Wcf Service With Json

Feb 13, 2010

I have developed a wcf service for asp.net ajax client. It includes the following steps.

(1) Created WCF sevice contract with the operation "DoWork()" which will take string as input and retun string as output.

(2)Implemented the above operation contract(attributed the implementation class with aspnetcompatibility requirement as enabled).

(3)Added the webscriptenabled to endpoint in web.config file.

(4)Hosted the wcf servie.

(5)Downloaded the javascript file from the service.(e.g.,http://localhost/service1.svc/js)

Client

(1)Opend new asp.net webapplication.

(2)Added the downloaded .js file.

(3)Given the scripts path for ajaxscript manager as both .js file and service url.

e.g

<asp:ScriptManager
ID="id1"
runat="server">
<Scripts>
<asp:ScriptReference
Path="http://localhost:3443/Service1.svc/js/"
/>
<asp:ScriptReference
Path="~/js1.js"
/>
</Scripts>
</asp:ScriptManager>

(4)With this I am unable to call service method

View 2 Replies

Pass A String To A Web Service Using JQuery / JSON / AJAX?

Oct 29, 2010

As it is now I create a JavaScript object and then stringify it, put it in a hidden textbox and my code behind can read this string. I then use JSON.NET to parse the string which works fine. I now try to use ajax to post it to my web service but have some issues with how to send the string. I have tried many ways but gets the common errors like

Invalid JSON primitive: myString.

So I checked this out [URL] and it works with hard coded values but I want to use a variable.

JavaScsript to create the object:

for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
var customer = new Object();
customer.id = row['id']
customer.name = row['name']
var customerString = JSON.stringify(customer);
$.ajax({
type: "POST",
url: "synchronise.asmx/synchroniseCustomers",
data: "synchroniseCustomers: " + customerString,
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (xhr, status) {
alert("An error occurred: " + status);
},
success: function (msg) {
alert("success");
}
});
}

WebMethod:

public void synchroniseCustomers(string customerString)
{
JObject o = JObject.Parse(customerString);
string id = (string)o["id"];
string name = (string)o["name"];

If I use data: '{ FirstName: "Dave", LastName: "Ward" }'

in the example above it works but I wish to pass on a string instead.

View 2 Replies

AJAX :: Use Return JSON Object From Web Service As A Declared Type?

Jan 3, 2010

I just hit the following issue: I am calling a web service that returns a serialized JSON object let's say: __type, FirstName, LastName (.net object Person with properties FirstName and LastName). __type's value is Test.Person

I have created a JS object using Type.registerNameSpace/registerClass called Demo.Person and it is registered on the page using the ScriptManager. Everything is working fine; I am able to get data from the server on the call back.

Is it possible to make the returned object from the web service be an instance of the declared JavaScript Demo.Person class? The idea would be to call a method like result.getFullName() on the client side without having to copy all the properties. This is just a simple scenario for more complex objects.

View 3 Replies

Any Webservice That Returns JSON?

May 11, 2010

Does anyone know of free webservice that returns a list in the form of JSON? I have searched many webservice sites but they all return xml. Geonames.org is not required.

View 3 Replies

WCF / ASMX :: WCF Service Returns Blank Data?

Jul 22, 2010

I'm new to WCF and this is definitely a rookie question. Why does my browser show/return nothing when I type this URL: http://localhost/service.svc/root, using the code below. I was hoping I would see an xml respone like: <double>56.78</double>. service.svc

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

<%@ ServiceHost Language="C#" Service="EssentialWCF.StockService" %>
using System;
using System.ServiceModel;
using System.ServiceModel.Web;

[code]...

View 6 Replies

Mvc Json - Color Always Returns Null

May 22, 2010

I am working on a mvc project, and having problem with json. i have created a demo project with list of colors

public JsonResult GetResult()
{
List<string> strList = new List<string>();
strList.Add("white");
strList.Add("blue");
strList.Add("black");
strList.Add("red");
strList.Add("orange");
strList.Add("green");
return this.Json(strList);
}
i am able to get these on my page, but when i try to delete one color, that is when i send the following using jquery
function deleteItem(item) {
$.ajax({
type: "POST",
url: "/Home/Delete/white",
data: "{}",
contentType: "application/json; charset=utf-8",
success: ajaxCallSucceed,
dataType: "json",
failure: ajaxCallFailed
});
}

the controler action public JsonResult Delete(string Color) {} Color always returns null, even if i have specified "/Home/Delete/white" in the url. i know i am doing something wrong or missing something, but not able to find out what.

View 4 Replies

C# - Why Does Silverlight Reference To Wcf Service Blow Up When Add Method To The Wcf Service That Returns Generic List

Aug 17, 2010

I have built a WCF Service that is being consumed by a Silverlight app. At first I created one method that was very simple:

public String SfTest()
{
return "SF Test";
}

No poblem. My silverlight app references my service and displays "SF Test" in a textbox. Now I add a method to my wcf service like this:

public List<String> GetTest()
{
List<String> list = new List<string>();
String a = "a";
list.Add(a);
String b = "b";
list.Add(b);
return list;
}

I update the reference to the service in my Silverlight app and the using statement in my xaml cs page throws an error like the service doesn't even exist although it is there. I am assuming the problem has to do with datatypes or serialization or something like that but it is driving me up the wall. Why can't I consume a simple generic list in my Silverlight app through the WCF service.

View 1 Replies

ASP WebMethod Returns JSON Wrapped In Quotes

Jun 8, 2010

I have an asp.net page with a WebMethod on it to pass JSON back to my javascript. Bellow is the web method:

[WebMethod]
public static string getData(Dictionary<string, string> d) {
string response = "{ "firstname": "John", "lastname": "Smith" }";
return response;
}

When this is returned to the client it is formatted as follows:

{ "d": "{ "firstname": "John", "lastname": "Smith" }" }

The problem is the double quotes wrapping everything under 'd'. Is there something I've missed in the web method or some other means of returning the data without the quotes? I don't really want to be stripping it out on the client everytime. Also I've seen other articles where this doesn't happen.

View 2 Replies

JQuery :: Sending Large Data From Json Based Webservice?

Mar 11, 2011

i am using combination of jquery and JSON based webservice in most of projets. Lately i am facing this problem. if the data returned from webservice is huge ajax call from jquery fails. yup i know i can implement paging etc etc but is there a way i can increase the limit to get more data from webservice with jquery ajax call?

View 2 Replies

WCF / ASMX :: Read Data From Json Web Service?

Dec 16, 2010

I'd like to read data server-side from a web service that outputs in json format. I haven't found any good examples that don't use jquery and are server-side.

Specifically I'm looking at the "weight" field from this api:

[URL]

PS: this is a spin off of another post at: [URL]

View 6 Replies

WCF / ASMX :: Return JSON Data From A 2.0 Web Service?

Sep 10, 2010

Just ramping up on JSON and JQuery and returning data to a ASP.NET web page from a web service using Ajax. The JQuery part is pretty straight-forward. However, when trying to return JSON formatted data instead of XML from a 2.0 web service, I'm stuck. The web service does have the System.Web.Script.Services.ScriptService attribute, so I can hit it via JavaScript; however, the web service always...always...returns data in XML format, no matter if I explicitly say I want JSON as the datatype in my JQuery code. So I don't know if this is an issue with the web service or the JQuery code. I posted this here, but realize that the category could be incorrect depending on where the issue is. Is there no way to return JSON data from a 2.0 web service? It's a production web service, so I can't change the code unfortunately.

View 3 Replies

JSON Data Cannot Be Matched To Web Service Signature?

Sep 1, 2010

I still can't seem to get this to work.I've tried string arrays object arrays dictionaries. I might be formatting my JSON incorrectly however I am using the labs_JSON plugin. If I remove my data and test the webservice it calls correctly. The : My code looks as follows :

HTML :

<div style="display: block; float: left;">
<asp:Repeater ID="rptMenuRecipeCategories" runat="server">
<HeaderTemplate>
<div class="recipeChecklistHeader">Menu Recipe Categories</div>

[Code]....

View 2 Replies

JQuery :: Call Asmx Service That Returns Multiple Data

Mar 3, 2011

I want to call .asmx service from jquery

.asmx service will return multiple data from database.

I need to get those data to jquery on client side

and then i need to put each data into their respective textfield on the client side

View 6 Replies

C# - Script Service For Parsing Json Data Fetched From The URL?

Aug 24, 2010

Does the script service means creating a webservice in asp.net?

View 1 Replies

Jquery - How To Send JSON Object To Web Service And Process The Data There

Oct 28, 2010

I am using the local database in web kit browsers and to get the data from the database I have the following code:

function synchronise() {
myDB.transaction(
function (transaction) {
transaction.executeSql("SELECT * FROM Patients;", [], synchroniseHandler, errorHandler);
}
);

[Code]....

View 1 Replies

WCF / ASMX :: Windows Communication Foundation Service Returning Xml / Json Data?

Aug 25, 2010

I Need by service contract to return the xml/json result depending on the request type. function which will convert my result set (i am using linq to sql) so that i do not need to create the xml format for the result set by iterating through the table row many times.What is the suitable way to do that.

I need a kind of short cut method which will convert the table data to xml result.Had i been using asp.net mvc i would have been able to generate the xml data by overriding the the ExecuteResult method in the ActionResult and giving Conetnt-Type = "text/xml" as OP.But since i am using Wcf i don't have the controller context(as controller context is the parameter that needs to be passed to Execute Result).

My present code for converting the table data to the xml format is below.

public XDocument UsersLists(string authToken)
{
bool IsAuthenticated = Authenticate(authToken);
XDocument xDoc = new XDocument();
XElement root = new XElement("Users");

[Code]....

I need to eliminate this way of generating xml for each table records.

View 1 Replies

C# - WCF Service Returns 400 Bad Request

Mar 18, 2011

I've got this application that works locally and when deployed and using a .mdf SQL Express database file (which I usually use for testing purposes). However, when I change it to work with our SQL Server 2008 the app works but the service doesn't. For example if in my code behind of a page I have a button that adds data to a table such as this it works fine:

public static string connString = @"Data Source=server1;Initial Catalog=Project;Integrated Security=True";
protected void btnAddProj_Click(object sender, EventArgs e)
{
using (var sqlc = new SqlConnection(connString))
{
sqlc.Open();
var cmd = sqlc.CreateCommand();
int intProjectID;
// Add the project info to the database
cmd.CommandText = "INSERT INTO tblProject VALUES(@ProjName,@ProjTeam,@ProjStart,@ProjEnd)";
cmd.Parameters.Add("ProjName", System.Data.SqlDbType.NVarChar).Value = txtProjName.Text;
cmd.Parameters.Add("ProjTeam", System.Data.SqlDbType.Int).Value = ddlTeamSupported.SelectedValue;
cmd.Parameters.Add("ProjStart", System.Data.SqlDbType.NVarChar).Value = txtStartDate.Text;
cmd.Parameters.Add("ProjEnd", System.Data.SqlDbType.NVarChar).Value = txtEndDate.Text;
cmd.ExecuteNonQuery();
}
}

My web.config is setup to use impersonation on that server and all works perfectly well. However, for my service the query doesn't seem to return anything and I get a 400 Bad Request error. The code for the jquery is:

$.ajax({
type: "POST",
async: false,
url: "Services/ProjectService.svc/test",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data);
}
});
And for the Service:
[ServiceContract]
public interface IProjectService
{
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json)]
ArrayList test();
}
public static string connString = @"Data Source=server1;Initial Catalog=Project;Integrated Security=True";
public ArrayList test()
{
var sqlc = new SqlConnection(connString);
sqlc.Open();
var cmd = sqlc.CreateCommand();
cmd.CommandText = "SELECT ProjectID FROM tblProject";
var reader = cmd.ExecuteReader();
ArrayList temparray = new ArrayList();
while (reader.Read())
{
temparray.Add(reader[0]);
}
sqlc.Close();
return temparray;
}

If instead of querying the database I have the service just return static data then it works fine. What could cause my service not to be able to connect to the database when the rest of the code behind for the app works?

View 3 Replies

WCF Service Returns Error 500 On / Js Request?

Jun 10, 2010

I have a wcf service that randomly begins to fail when requesting the autogenerated javascript that wcf supports making. But I have no luck tracking down why. The js thing is part of the wcf featureset, so I dont know how it can suddenly begin to fail and be unable to work until IIS is recycled.

The http log gives me:

2010-06-10 09:11:49 W3SVC2095255988 myip GET /path/myservice.svc/js _=1276161113900 80 - ip browser 500 0 0
So its an error 500, and that is about the only thing I can figure out. The event log contains no information.

Requests to /path/myservice.svc works just fine. After recycling IIS it works again, and some days later it begins to fail until I recycle IIS.

<service
name="path.myservice"
behaviorConfiguration="b">
<endpoint
address=""
behaviorConfiguration="eb"
binding="webHttpBinding"
contract="path.Imyservice" />
</service>
...
<endpointBehaviors>
<behavior name="eb">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="b">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>

I dont see any problems in the web.config settings either.

Edit:

Just to make it clear - It is the generation of javascript that fails, my code is never invoked. Calls to the service works just fine.

View 2 Replies

Web Service Returns IndexOutOfRangeException With Arguments?

Dec 15, 2010

I have the following web service:

[ScriptService]
public class Handler : WebService {

[WebMethod]
public void method1() {

string json = "{ "success": true }";

System.Web.HttpContext.Current.Response.Write(json);

[code]...

The first method accepts a traditional html form post and response writes a JSON string to the page.The second method accepts a JSON value posted via AJAX and returns a serialized object.Both these methods work fine on their own but when put together in the same web service I get this error when calling method1:

System.IndexOutOfRangeException: Index was outside the bounds of the array.

When I remove the arguments from method2 they work.Can anyone suggest why this is happening?

Edit:The problem spans from the argument type of method2. If I change it to a string or simple data type it works fine.As Joel suggests it's probably because Dictionaries can't be serialized.This doesn't seem to affect my requests sent by ajax and only breaks direct form posts to this handler.Therefore my workaround is to put the form post handlers in a separate file by themselves.Not ideal but works for my application.

View 1 Replies

Patterns For A Data File Based WCF REST Web Service?

Mar 15, 2011

We have an existing, proprietary data processing application that runs on one of our servers and we wish to expose it as a web service for our clients to submit jobs remotely. In essence, the system takes a set of configuration parameters and one or more data files (the number of files depends on the particular configuration template, but the normal config is 2 files). The application then takes the input files, processes them, and outputs a single result data file (all files are delimited text / CSV or tab).

We want to now expose this process as a service. Based on our current setup and existing platforms, we are fairly confident that we want to go with WCF 4.0 as the framework and likely REST for the service format, though a SOAP implementation may be required at some point.

Although I am doing a lot of reading on SOA, WCF and REST, I am interested in other thoughts on how to model this service. In particular, the one-to-many relationship of job to required files for input. It seems pretty trivial to model a "job" in REST with the standard CRUD commands. However, the predefined "job type" parameter defines the number of files that must be included. A job type of "A" might call for two input files, while "B" requires 3 before the job can run.

Given that, what is best way to model the job? Do I include the multiple files in the initial creation of the job? Do I create a job and then have an "addFile" method where by I can then upload the necessary number of files?

The jobs will then have to run asynchronously because they can take time. Once complete, is it best to then just have a status field in the job object and require the client to regularly query the system for job status, or perhaps have the client provide a URL to "ping" when the job is complete?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved