View Full Version : Connecting to Webservices(ASP.NET Web service and WCF web service)

24 Nov 2011, 5:37 AM
I am using the following ExtJS framework code to fetch data from WebService

var param= { myString:'suchee' };
method: 'GET',
url: '', jsonData : Ext.encode(param), headers: { 'Content-Type': 'application/json;charset=utf-8' },
success: function (response, request) { alert('hit!') ; },
failure: function (response, request) { alert('not hit!'); }});

The service method is as below

[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public string checkuser(string myString) {
return "true"

The service is accessible but it fails when called from above code in ExtJs.
I also tried connecting to WCF services but nothing seem to work.

24 Nov 2011, 5:51 AM
So what does it respond?

24 Nov 2011, 8:58 PM
It goes to the failure function and shows alert message "not Hit!". The response.status is 0 or 500. I was able to call methods without parameters. But when i send parameter, the call fails

29 Nov 2011, 9:12 AM
for asmx maybe this code helps, one different is that you are using Get and this one Post.

var jsonData =
grantId: grantId,
sourceTypeId: 2

url: 'ws/ServiceName.asmx/NotifyApprove',
method: 'post',
'Content-Type': 'application/json;charset=utf-8'
jsonData: jsonData,
success: function(response, options)
response = eval('results = ' + response.responseText);
var sequenceId = parseInt(response.d.SequenceId); //The response is wrapped in d
//do something if you need
failure: function(response, options)
response = eval('results = ' + response.responseText);

In the service

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False, XmlSerializeString:=False)> _
public object NotifyApprove(int? grantId, int? sourceTypeId)
return new {SequenceId = sequenceId};

29 Nov 2011, 9:25 AM
for WCF:

The service:

namespace Application.Service
[ServiceBehavior(UseSynchronizationContext = false,
ConcurrencyMode = ConcurrencyMode.Multiple,
InstanceContextMode = InstanceContextMode.PerCall),
AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class VendorService : IVendorService
public List<Vendor> RetrieveMultiple(int start, int limit, string sort, string dir)
//I don't do any manual serialization
return new Vendor();
}/CODE]The contract:


public interface IVendorService
[WebInvoke(ResponseFormat=WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
List<Vendor> RetrieveMultiple(int start, int limit, string sort, string dir);

SVC File:

<%@ ServiceHost Service="Application.Service.VendorService" %>Web.config
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behavior name="jsonBehavior">
<enableWebScript />
<webHttp />
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />

<service behaviorConfiguration="DefaultServiceBehavior" name="Application.Service.VendorService">
<endpoint behaviorConfiguration="jsonBehavior" address="" binding="webHttpBinding" contract="Application.Service.Contracts.IVendor" />
</service>In wcf no more "d" for wrapped responses.I leave you this reference: Just make sure you request looks like this:29667

8 Dec 2011, 8:15 PM
Yes, I was able to connect to the service by updating behavior configuration in the web.config file. Thanks for your post :)

10 Dec 2011, 3:32 AM
I am able to connect to the above wcf service with localhost url but am not able to connect when ip address of the system is given in Ext.Ajax.Request. Please let me know how to connect to WCF through IP address. I am able to access the service with IP address