Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: WCF
I have lot tried post call to wcf service but its not working,but get call is working's code:-
WCF IService->
    public interface IService
        void DoWork();
        [WebInvoke(Method = "GET", UriTemplate = "/TestMethod", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        string TestMethod();
        [WebInvoke(Method = "POST", UriTemplate = "/TestMethod_FORPOST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        string TestMethod_FORPOST(string param1);

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
   [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
   public class Service : IService
       public void DoWork()
       public string TestMethod()
           return "Success";
       public string TestMethod_FORPOST(string param1)
           return "SuccessFullyPosted";

Web Confi:- <!--CustomSettingsForWCF-->
        <binding name="webBinding" maxreceivedmessagesize="2147483647" crossdomainscriptaccessenabled="true">
                 maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
          <readerquotas maxstringcontentlength="2147483647" maxarraylength="2147483647" />
          <!--<security mode="Transport">
              <extendedprotectionpolicy policyenforcement="Never" />
      <service behaviorconfiguration="Service" name="WCF_TEST_APPLICATION_WITH_AJAXCALL.Service">
        <endpoint address="" behaviorconfiguration="webEndpoint">
                  binding="webHttpBinding" bindingConfiguration="webBinding" name="web"
                  bindingNamespace="" contract="WCF_TEST_APPLICATION_WITH_AJAXCALL.IService" />
        <behavior name="webEndpoint">
          <webhttp helpenabled="true" defaultbodystyle="Wrapped" defaultoutgoingresponseformat="Json" />
        <behavior name="Service">
          <servicemetadata httpgetenabled="true" />
          <servicedebug includeexceptiondetailinfaults="false" />
          <!--<userequestheadersformetadataaddress />-->
    <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" />
    <modules runallmanagedmodulesforallrequests="true" />
Another application throughout Call method:-
           var  WCFurl = "http://localhost:49212/Service.svc/TestMethod_FORPOST";
            var datar = { param1: "abc" };
                type: "POST",
                //contentType: "application/json; charset=utf-8",
                url: WCFurl,
                data: JSON.stringify(datar),
                dataType: "json",
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
                success: function (msg) {
                error: function (xhr, status, error) {
                    alert(xhr.status + " " + status + " " + error);
                complete: function (data) {
above code is working fine for get call but not for post call, please give me suggestion, how can i do with post call?
Posted 3-Oct-12 22:03pm
Edited 3-Oct-12 23:25pm
(no name)180.4K

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web04 | 2.8.150129.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100