代码之家  ›  专栏  ›  技术社区  ›  Malice

从中检索XML数据时出现问题ASP.NETWeb服务

  •  0
  • Malice  · 技术社区  · 14 年前

    我试图调用一个Web服务从数据库中检索一些XML数据。如果我使用静态文件,那么Ajax调用可以正常工作,例如:

    $.ajax({
        type: "GET",
        url: "test2.xml",
        data: buildXMLDataRequestObject(),
        dataType: "xml",
        success: getXMLDataSucceeded,
        error: getXMLDataFailed
    });
    

    但当我尝试调用Web服务时失败,例如:

    $.ajax({
        type: "POST",
        url: "Services/CheckOutService.svc/GetXMLData",
        data: buildXMLDataRequestObject(),
        dataType: "xml",
        success: getXMLDataSucceeded,
        error: getXMLDataFailed
    });
    

    “传入消息具有 意外的消息格式“Raw”。这个 的预期消息格式 因为WebContentTypeMapper 未在绑定上配置。 WebContentTypeMapper了解更多 详细信息。”

    GetXMLData方法如下所示:

    // Interface
    [OperationContract]
    [WebInvoke(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    string GetXMLData(XMLDataRequest request);
    ...
    // Implementation
    public string GetXMLData(XMLDataRequest request)
    {
        request.ShopperId = ShopperId;
        return checkOutManager.GetXMLData(request);
    }   
    

    非常

    第1行,位置1。

    我尝试过contentType:“text/xml”和contentType:“application/xml”,两者都给出了相同的错误。

    编辑:昨天(8月30日)我注意到,如果省略ajax调用的data参数,服务调用就会成功。我想JSON对象有点问题。目前,我已经在应用程序的服务器端实现了这个功能,但我确实打算在有时间的时候再讨论一下。

    1 回复  |  直到 14 年前
        1
  •  0
  •   Jon Hanna    14 年前

    我的第一个猜测是内容类型是错误的。当你用小提琴手或类似的工具看这条河时,你看到了什么?