使用dojo XHR post调用WCF服务



我已经能够调用方法在我的。net wcf服务使用dojo xhr。但是现在我需要使用xhr post将一个类传递给同一个wcf服务中的一个方法。当我使用下面的参数是空的,当它到达我的。net方法:

dojo XHR call:

AirVacInspectionInsert: function (url, av) {//url is valid, av is javascript object identical to class input parameter for .Net method validated json format
        xhr.post({//send data
            url: url,
            postData: dojo.toJson(av),
            contentType: "application/json",
            handleAs: "json",
            load: function (result) {
                var InspDataID = result.AirVacInspectionInsertResult;
            },
            error: function (err) { }
        }); 

。Net:接口:

 [OperationContract]
    [WebInvoke(Method = "POST",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "AirVacInspectionInsert/")]
        int AirVacInspectionInsert(AVInspectionData av);

。净方法:

  public int AirVacInspectionInsert(AVInspectionData av)//av is null
         {
             //insert new air vac inspection
            int ID = 0;
            //DataSet ds = DBCalls.AirVacInspectionInsert(av);
            //ID = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            return ID;
         }

web . config:

    <?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="SARIService.Service1" behaviorConfiguration="ServiceBehavior">
        <endpoint address="" binding="webHttpBinding" contract="SARIService.IService1"     behaviorConfiguration="web">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

任何想法?是否有一些参数我错过了获得服务来读取发布的数据?

谢谢

问题出在。net接口上。I changed

 BodyStyle = WebMessageBodyStyle.Wrapped,

 BodyStyle = WebMessageBodyStyle.Bare,

并且成功了

最新更新