views:

41

answers:

1

I have the following ajax call to webservice to pass json data and get response xml data, when i debug the code the flow is not reaching the webservice

var keyword2 = "{\"keyword1\":\"" + keyword1 + "\",\"streetname\":\"" + address1 + "\",\"lat\":\"" + lat + "\",\"lng\":\"" + lng + "\",\"radius\":\"" + radius + "\"}";
                    $.ajax({
                        type: "POST",
                        async: false,
                        url: "/blockseek3-9-2010/JsonWebService.asmx/GetList",
                        data: keyword2,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        failure: ajaxCallFailed,
                        success: function(response) {
                            GDownloadUrl(response, function(data) {
                                var xml = GXml.parse(response.xml);
                                var markers = xml.documentElement.getElementsByTagName('marker');
                                map.clearOverlays();

                            var sidebar = document.getElementById('sidebar');
                            sidebar.innerHTML = '';
                            alert(markers.length);

                            if (markers.length == 0) {
                                sidebar.innerHTML = 'No results found.';
                                map.setCenter(new GLatLng(40, -100), 4);
                                return;
                            }

                            var bounds = new GLatLngBounds();
                            for (var i = 0; i < markers.length; i++) {
                                var name = markers[i].getAttribute('name');
                                var address = markers[i].getAttribute('address');
                                var distance = parseFloat(markers[i].getAttribute('distance'));
                                var point = new GLatLng(parseFloat(markers[i]
                    .getAttribute('lat')), parseFloat(markers[i]
                    .getAttribute('lng')));
                                var imagepath = markers[i].getAttribute('imagepath');

                                var marker = createMarker(point, name, address, imagepath);
                                map.addOverlay(marker);
                                var sidebarEntry = createSidebarEntry(marker, name, address,
                    distance, imagepath);
                                sidebar.appendChild(sidebarEntry);


                                bounds.extend(point);
                            }
                            map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
                        });

                    }

                });
            });

This will be my code snippet on webservice side

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public XmlDocument GetList(string keyword1, string streetname, string lat, string lng, string radius)
    {

  XmlDocument xmlDoc=  CreateXML( keyword1,streetname,lat,lng,radius);
    //save file to application folder which will be refferd by client application
  xmlDoc.Save(@"D:\blockseek3-9-2010\Block3.xml");
  return xmlDoc;

}
+1  A: 

Two things.

  1. Are you sure that the URL /blockseek3-9-2010/JsonWebService.asmx/GetList is correct, this is relative to the page that the Ajax call is being made from. What is the full URL to the page running this query?

  2. Your WebMethod has specified a Json response format [ScriptMethod(ResponseFormat = ResponseFormat.Json)] but in the Javascript code you are accessing response.xml which will be undefined for a Json object. By your description, I think you need to change the WebMthod to [ScriptMethod(ResponseFormat = ResponseFormat.Xml)], you can still use Json to invoke the WebMethod from the client side.

Note: Point 2 is not related to why you can't call the web service, this point relates to an issue you will face once you resolve the core issue of not actually hitting the WebMethod.

Chris Taylor
Thanks for the reply , i have changed the code as you suggested
mahesh
I have changed webservice call like $.ajax({ type: "POST", async: false, url: "http://localhost:2330/blockseek7-9-2010/JsonWebService.asmx/GetList", data: keyword2, contentType: "application/json; charset=utf-8", dataType: "json", failure: ajaxCallFailed, success: ajaxCallSucceed });
mahesh
In ajaxcallsucceed i have written like GXml is google api for parsing xml document,I can call webservice but i have problem with response var xml = GXml.parse(response.xml); var markers = xml.documentElement.getElementsByTagName('marker'); map.clearOverlays(); var sidebar = document.getElementById('sidebar'); sidebar.innerHTML = ''; alert(markers.length); .....
mahesh
@mahesh, this might be the problem I pointed out in point 2 in my response. Did you change the ScriptMethod attribute `[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]`?
Chris Taylor
Ya i haved changed the response format to
mahesh
[WebMethod] [ScriptMethod(ResponseFormat=ResponseFormat.Xml)]
mahesh
Is their any problem with client side syntax for capturing that particular xml output ,using google api like GDownloadUrl,GXml to capture the response output
mahesh
@mahesh, unfortunatly I am not familiar with the Google API. Have you checked in the debugger and confirmed that the client is at least receiving the XML that you expect?
Chris Taylor