使用dojo xhr post调用wcf服务

时间:2014-06-26 18:57:58

标签: c# javascript ajax wcf dojo

我已经能够使用dojo xhr.get在我的.Net wcf服务中调用methodes,但是现在我需要使用xhr post将类传递给同一个wcf服务中的方法。当我使用以下内容时,参数在到达我的.Net方法时为null:

dojo xhr电话:

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);

.Net方法:

  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>

有什么想法吗?我是否缺少一些参数来让服务读取发布的数据?

由于

1 个答案:

答案 0 :(得分:0)

问题出在.Net界面上。我改变了

 BodyStyle = WebMessageBodyStyle.Wrapped,

 BodyStyle = WebMessageBodyStyle.Bare,

并且有效

相关问题