Ajax call to WCF Web Service returns 400 Bad Request -


possible duplicate:
wcf web service returns “bad request” error when invoked through javascript

i have simple wcf web service service1 1 method test() returns string. have deployed web service on test machine, when try invoke test method browser 400 bad request error. same happens when try invoke method through ajax request. surprisingly, method returns correct result when invoked through wcftestclient.

here code:

[servicecontract] public interface iservice1 {     // method can called list of page sets per report.     [operationcontract]     [webget]     string test(); }         public class service1 : iservice1 {     public string test()     {         return "test";     } } 

this ajax request:

 var serverurl1 = 'http://' + baseurl + ':86/service1.svc';   function getteststring()  {         var methodurl = serverurl1 + "/test";         $.ajax({     async: false,                 type: "get",     contenttype: "application/json; charset=utf-8",     datatype: "json",             url: methodurl,                 beforesend: function (xmlhttprequest) {         //ensures results returned json.               xmlhttprequest.setrequestheader("accept", "application/json");                 },     success: function (data) {         showqrgslides(data.d);     },     error: function (xmlhttprequest, textstatus, errorthrown) {         alert("error: getavailablepages() check browsers javascript console more details." + " \n xmlhttprequest: " + xmlhttprequest + " \n textstatus: " + textstatus + " \n errorthrown: " + errorthrown);     }   });   } 

here web.config file web service:

<?xml version="1.0"?> <configuration>  <system.web> <compilation debug="true" targetframework="4.0" /> <customerrors mode="off"/> </system.web> <system.servicemodel> <behaviors>   <servicebehaviors>     <behavior>       <!-- avoid disclosing metadata information, set value below false , remove metadata endpoint above before deployment -->       <servicemetadata httpgetenabled="true"/>       <!-- receive exception details in faults debugging purposes, set value below true.  set false before deployment avoid disclosing exception information -->       <servicedebug includeexceptiondetailinfaults="false"/>     </behavior>   </servicebehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled="true" /> </system.servicemodel> <system.webserver> <modules runallmanagedmodulesforallrequests="true"/> </system.webserver>  </configuration> 

this simple web.config gets automatically generated. unable figure out why simple web service method not accessible through browser or ajax. same method returns result when accessed through wcftestclient.

any inputs appreciated! thanks.

you need add service section web.config file. host not know want use webhttpbinding unless tell him.

<services>   <service name="service1">     <endpoint address=""               binding="webhttpbinding"               contract="iservice1" />   </service> </services> 

link below provides detailed instructions hosting service in iis (with wshttpbinding). need use webhttpbinding instead of wshttpbinding - http://msdn.microsoft.com/en-us/library/ms733766.aspx


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -