【问题标题】:call wcf service using dojo xhr post使用 dojo xhr post 调用 wcf 服务
【发布时间】:2014-06-26 18:57:57
【问题描述】:

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

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>

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

谢谢

【问题讨论】:

  • 我在界面的 uri 模板属性上创建了一个类型。 uri 模板应该是:UriTemplate = "AirVacInspectionInsert")] 而不是 UriTemplate = "AirVacInspectionInsert/")]。但这并没有解决问题——仍然没有读取发布的数据

标签: c# javascript ajax wcf dojo


【解决方案1】:

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

 BodyStyle = WebMessageBodyStyle.Wrapped,

 BodyStyle = WebMessageBodyStyle.Bare,

成功了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-18
    • 2012-03-05
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多