WCF 400 bad request error

UaeDarling

New Member
I have two Wcf restful services 1. suggest and 2. Search. The suggest service works fine but I get a 400 error when I use Search service. Search service is mocked to return from an xml. The search service parses xml and returns the object. Below is the code.The Interface:\[code\]public interface IAirSearchResultsnew { [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/GetAirsearchResults?" + "FT={FT}&SL={SL}&EL={EL}&SD={SD}&ED={ED}&FD={FD}&AD={AD}&CD={CD}&IN={IN}&" + "CL={CL}&DT={DT}&RT={RT}")] [OperationContract] airsearchresult GetAirSearchResult(string FT, string SL, string EL, string SD, string ED, string FD, string AD, string CD, string IN, string CL, string DT, string RT); }\[/code\]The Service:\[code\]namespace Rickshaw.Services{ // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "AirSearchResultsnew" in code, svc and config file together. public class AirSearchResultsnew : IAirSearchResultsnew { public airsearchresult GetAirSearchResult(string flightType, string from, string to, string start, string end, string flexibleDates, string adults, string children, string infants, string classPreference, string departTimePreference, string returnTimePreference) { #region Parameters read and convert to Proper form var startDate = start.Split('/'); var endDate = end.Split('/'); var SD = new DateTime(int.Parse(startDate[2]), int.Parse(startDate[0]), int.Parse(startDate[1])); var ED = new DateTime(int.Parse(endDate[2]), int.Parse(endDate[0]), int.Parse(endDate[1])); var FD = bool.Parse(flexibleDates); var AD = int.Parse(adults); int CD = 0; CD = int.Parse(children == "select" ? "0" : children); int IN = 0; IN = int.Parse(infants == "select" ? "0" : infants); var CL = string.Empty; CL = classPreference == "undefined" ? "NA" : classPreference; var DT = string.Empty; DT = departTimePreference == "undefined" ? "NA" : departTimePreference; var RT = string.Empty; RT = returnTimePreference == "undefined" ? "NA" : returnTimePreference; #endregion #region Mocked Service var reader = XmlReader.Create(@"C:\Users\Yash\Documents\Visual Studio 2010\Projects\WcfService1\Samples\sample2.xml"); XmlSerializer serializer = new XmlSerializer(typeof(airsearchresult)); var airsearchresults = serializer.Deserialize(reader) as airsearchresult; return airsearchresults; #endregion } }}\[/code\]The config:\[code\]<configuration> <system.web> <trace enabled="true" requestLimit="100" /> <customErrors defaultRedirect="~/Default.aspx" /> <authorization> <allow roles="Administrators" /> </authorization> <roleManager enabled="true" /> <authentication mode="Forms" /> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="Suggest"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="999999999" /> </behavior> <behavior name="AirSearch"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false"/> <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="999999999"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="Rickshaw.Services.Suggest"> <webHttp/> </behavior> <behavior name="Rickshaw.Services.AirSearchResultsnew"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <services> <service name="Rickshaw.Services.Suggest" behaviorConfiguration="Suggest"> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="Rickshaw.Services.Suggest" contract="Rickshaw.Services.ISuggest" /> </service> <service name="Rickshaw.Services.AirSearchResultsnew" behaviorConfiguration ="AirSearch"> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="Rickshaw.Services.AirSearchResultsnew" contract ="Rickshaw.Services.IAirSearchResultsnew" /> </service> </services> </system.serviceModel></configuration>\[/code\]and the Javascript code:\[code\]var query = "http://localhost:4696/Services/AirSearchResultsnew.svc/GetAirSearchResults?" + "FT=" + FT + "&SL=" + SL + "&EL=" + EL + "&SD=" + SD + "&ED=" + ED + "&FD=" + FD + "&AD=" + AD + "&CD=" + CD + "&IN=" + IN + "&" + "CL=" + CL + "&DT=" + DT + "&RT=" + RT + "";var result = getAirSearchResults(query);function getAirSearchResults(query) { var module = { data: [null] }; $.ajax({ url: query, success: function (e) { console.log(e); module.data = http://stackoverflow.com/questions/10770165/e; }, async: false, error: function (XHR, textStatus, errorThrown) { alert(textStatus +":" + errorThrown); } }); console.log(module.data); return module.data;};\[/code\]And importantly Icreated the service Proxy from xsd provided hereand the XML for returning data provided hereI am sure that the call hits the service and the service parses XML properly as I have debugged it through the service but I dont understand where the problem is.. Any help?
 
Back
Top