0

我正在尝试更新我们的股票,认为 Magento API 使用 Progress 4GL (OpenEdge 10.2B)

到目前为止一切顺利,即:如果 SKU 匹配,我可以更新库存。但如果不是,它不会返回错误。

因此,我研究了 ABL 如何管理 SAOP 故障错误,并找到了一些我尝试实现的示例。但无济于事。

我的代码如下:

DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.
DEFINE VARIABLE hMage_Api_Model_Server_V2_HandlerPortType AS HANDLE NO-UNDO.
DEFINE VARIABLE username AS CHARACTER NO-UNDO.
DEFINE VARIABLE apiKey AS CHARACTER NO-UNDO.
DEFINE VARIABLE stock AS CHARACTER NO-UNDO.
DEFINE VARIABLE codigo AS CHARACTER NO-UNDO.
DEFINE VARIABLE loginReturn AS CHARACTER NO-UNDO.
DEFINE VARIABLE product AS CHARACTER NO-UNDO.
DEFINE VARIABLE data AS LONGCHAR NO-UNDO.
DEFINE VARIABLE resultado AS INTEGER NO-UNDO.
DEFINE VARIABLE SOAP-FAULT-CODE AS CHARACTER NO-UNDO.
DEFINE VARIABLE SOAP-FAULT-DETAIL AS CHARACTER NO-UNDO.
DEFINE VARIABLE iError AS INTEGER     NO-UNDO.
DEFINE VARIABLE cError AS CHARACTER   NO-UNDO.

DO ON ERROR UNDO, THROW:
CREATE SERVER hWebService.

 /* TODO: Definir variaveis globais */
username = 'username'.
apiKey  = 'password'.

hWebService:CONNECT(" -WSDL 'http://www.medicalemcasa.com/api/v2_soap?wsdl'").

RUN Mage_Api_Model_Server_V2_HandlerPortType SET hMage_Api_Model_Server_V2_HandlerPortType ON hWebService.
RUN login IN hMage_Api_Model_Server_V2_HandlerPortType(INPUT username, INPUT apiKey, OUTPUT loginReturn).


product = "100asda001a".
data = "
       <data>
       <qty>'250'</qty>
       </data>
       ".

PROCEDURE catalogInventoryStockItemUpdate:
  DEFINE INPUT PARAMETER data AS CHARACTER NO-UNDO.
END PROCEDURE.

RUN catalogInventoryStockItemUpdate IN hMage_Api_Model_Server_V2_HandlerPortType (INPUT loginReturn, INPUT product, INPUT data, OUTPUT resultado).
DISPLAY resultado.

CATCH mySoapErrorObject AS Progress.Lang.SoapFaultError:
    DO iError = 1 TO mySoapErrorObject:NumMessages:
        cError = cError + mySoapErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySoapErrorObject.
END CATCH.

CATCH mySystemErrorObject AS Progress.Lang.SysError:
    DO iError = 1 TO mySystemErrorObject:NumMessages:
        cError = cError + mySystemErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySystemErrorObject.
END CATCH.

FINALLY:
IF cError <> "" THEN DO:
    MESSAGE "Errors occured:" SKIP
        cError
        VIEW-AS ALERT-BOX ERROR.
END.
END FINALLY.
END.

hWebService:DISCONNECT().
DELETE OBJECT hWebService.
4

1 回答 1

1

在这些 API 中,我使用 SOAP 错误仅在出现“更大”错误时才会发生。例如,如果 web 服务关闭、登录条件不满足、数据类型错误等。通常返回值在响应中而不是在 SOAP 信封中。

难道将不存在的产品设置为库存0就可以了吗?如果您尝试将其设置为 1 会发生什么?也许您应该从 PHP(或您通常使用的任何语言)仔细检查 Web 服务实际上提供了您在这种情况下所期望的代码?

否则,您应该查看创建的 wsdl 文档 - 您是否 100% 确定结果参数(代码中的结果)是一个整数,而不是任何形式的更复杂的 xml 文档(基本上是一个对象)?如果它真的是 HANDLE,则可能是没有运行时错误,但没有将值插入 INTEGER。

此外,您应该删除所有当前的错误处理并将其替换为更通用的错误处理方式(并在需要时使该代码更具体,而不是从文档中的示例中工作):

DEFINE VARIABLE iError AS INTEGER     NO-UNDO.
DEFINE VARIABLE cError AS CHARACTER   NO-UNDO.

CATCH mySoapErrorObject AS Progress.Lang.SoapFaultError:
    DO iError = 1 TO mySoapErrorObject:NumMessages:
        cError = cError + mySoapErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySoapErrorObject.
END CATCH.

CATCH mySystemErrorObject AS Progress.Lang.SysError:
    DO iError = 1 TO mySystemErrorObject:NumMessages:
        cError = cError + mySystemErrorObject:getMessage(iError) + "~n".
    END.
    DELETE OBJECT mySystemErrorObject.
END CATCH.

并插入 FINALLY 块:

IF cError <> "" THEN DO:
    MESSAGE "Errors occured:" SKIP
        cError
        VIEW-AS ALERT-BOX ERROR.
END.
于 2013-10-24T10:52:35.700 回答