Progress 4GL Web服务程序

时间:2013-10-23 17:46:50

标签: web-services api progress-4gl openedge

我正在尝试更新我们的股票,认为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.

1 个答案:

答案 0 :(得分:1)

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

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

否则你应该看看创建的wsdl文档 - 你是否100%确定结果参数(你的代码中的结果)是一个INTEGER而不是任何形式的更复杂的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-block:

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