1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    11
    Vote Rating
    0
    sucheendarnath is on a distinguished road

      0  

    Exclamation Connecting to Webservices(ASP.NET Web service and WCF web service)

    Connecting to Webservices(ASP.NET Web service and WCF web service)


    I am using the following ExtJS framework code to fetch data from WebService

    var param= { myString:'suchee' };
    Ext.Ajax.request({
    method: 'GET',
    url: 'http://192.168.0.98/webservices/WebService.asmx/checkuser', 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

    [WebMethod]
    [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.

  2. #2
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,783
    Vote Rating
    112
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    So what does it respond?

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    11
    Vote Rating
    0
    sucheendarnath is on a distinguished road

      0  

    Default


    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
    Last edited by sucheendarnath; 25 Nov 2011 at 4:39 AM. Reason: detailing

  4. #4
    Sencha User brittongr's Avatar
    Join Date
    Jun 2007
    Location
    Panama
    Posts
    109
    Vote Rating
    3
    brittongr is on a distinguished road

      0  

    Default


    for asmx maybe this code helps, one different is that you are using Get and this one Post.

    Code:
            var jsonData = 
            {
                grantId: grantId,
                sourceTypeId: 2
            };
    
    
            Ext.Ajax.request(
            {
                url: 'ws/ServiceName.asmx/NotifyApprove',
                method: 'post',
                headers: 
                {
                    '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

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

    My Extensions:
    Ext.ux.NumericField: Number field with support for currencySymbol, thousand separator, international...
    Ext.ux.PagerSizeSelector: A plugin that allows the change page size with just one click.
    Ext.ux.FieldAccess: A plugin to let the user know which fields are editable.

  5. #5
    Sencha User brittongr's Avatar
    Join Date
    Jun 2007
    Location
    Panama
    Posts
    109
    Vote Rating
    3
    brittongr is on a distinguished road

      0  

    Default


    for WCF:

    The service:


    [CODE]
    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:

    Code:
      [ServiceContract]            
        public interface IVendorService
        {
           [OperationContract]
           [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
    HTML Code:
    <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <behaviors>
          <endpointBehaviors>
            <behavior name="jsonBehavior">
              <enableWebScript />
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="DefaultServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
      <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:request.jpg
    Greivin Britton

    My Extensions:
    Ext.ux.NumericField: Number field with support for currencySymbol, thousand separator, international...
    Ext.ux.PagerSizeSelector: A plugin that allows the change page size with just one click.
    Ext.ux.FieldAccess: A plugin to let the user know which fields are editable.

  6. #6
    Sencha User
    Join Date
    Nov 2011
    Posts
    11
    Vote Rating
    0
    sucheendarnath is on a distinguished road

      0  

    Default I am able to connect to WCF

    I am able to connect to WCF


    Yes, I was able to connect to the service by updating behavior configuration in the web.config file. Thanks for your post

  7. #7
    Sencha User
    Join Date
    Nov 2011
    Posts
    11
    Vote Rating
    0
    sucheendarnath is on a distinguished road

      0  

    Exclamation Unable to connect to wcf with IP address

    Unable to connect to wcf with IP address


    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

Thread Participants: 2

Tags for this Thread