问题描述
我想更新我们的股票就想到了用进步4GL(OpenEdge 102亿)
Magento的API到目前为止好,即:我可以更新库存,如果SKU匹配。但如果不是,它不返回一个错误。
所以,我看着ABL如何管理SAOP故障的错误,并发现了一些例子,我试图执行。但无济于事。
我的新 code是如下:
定义变量hWebService按规定办理NO-UNDO。
定义变量hMage_Api_Model_Server_V2_HandlerPortType按规定办理NO-UNDO。
定义变量名以字符NO-UNDO。
定义变量apiKey为字符NO-UNDO。
定义变量股票作为字符NO-UNDO。
定义变量codigo为字符NO-UNDO。
定义变量loginReturn为字符NO-UNDO。
定义变量产品为字符NO-UNDO。
定义为LONGCHAR NO-UNDO可变数据。
定义变量resultado AS INTEGER NO-UNDO。
定义变量SOAP的容错code作为CHARACTER NO-UNDO。
定义变量SOAP的故障详细的CHARACTER NO-UNDO。
定义变量IERROR AS INTEGER NO-UNDO。
定义变量cError为字符NO-UNDO。做错误UNDO,扔:
CREATE SERVER hWebService。 / * TODO:Definir variaveis globais * /
用户名='用户名'。
apiKey ='密码'。hWebService:CONNECT(-wsdlhttp://www.medicalemcasa.com/api/v2_soap?wsdl')。RUN Mage_Api_Model_Server_V2_HandlerPortType SET hMage_Api_Model_Server_V2_HandlerPortType ON hWebService。
RUN登录hMage_Api_Model_Server_V2_HandlerPortType(INPUT用户名,输入apiKey,OUTPUT loginReturn)。
产品=100asda001a。
数据=
<数据>
<&数量GT;'250'< /数量>
< /数据>
。程序catalogInventoryStockItemUpdate:
定义输入参数数据作为字符NO-UNDO。
端程序。RUN catalogInventoryStockItemUpdate IN hMage_Api_Model_Server_V2_HandlerPortType(INPUT loginReturn,输入产品,输入数据,输出resultado)。
DISPLAY resultado。CATCH mySoapErrorObject AS Progress.Lang.SoapFaultError:
DO I误差= 1 TO mySoapErrorObject:NumMessages:
cError = cError + mySoapErrorObject:的getMessage(IERROR)+〜N。
结束。
删除对象mySoapErrorObject。
END CATCH。CATCH mySystemErrorObject AS Progress.Lang.SysError:
DO I误差= 1 TO mySystemErrorObject:NumMessages:
cError = cError + mySystemErrorObject:的getMessage(IERROR)+〜N。
结束。
删除对象mySystemErrorObject。
END CATCH。最后:
IF cError<> 那DO:
MESSAGE错误发生:SKIP
cError
VIEW-ALERT AS-BOX错误。
结束。
end最后。
结束。hWebService:断开()。
删除对象hWebService。
在这些API的我和SOAP错误的工作时,有一个大的错误只发生。例如,如果web服务已关闭,登录标准不满足,数据类型是错误等。通常一个返回值,而在响应,而不是在SOAP信封。
难道它只是确定一个不存在的产品设置为0的库存?如果你尝试将它设置为1,会发生什么?也许你应该增加一倍,从PHP(或任何语言,你通常工作)的Web服务实际上提供了code你在这种情况下,期望检查?
否则你应该看看创建的WSDL的文档 - 你是100%肯定的结果参数(resultado你code)是INTEGER,而不是任何形式的更复杂的XML文档的(对象基本上)?如果它是一个真正的处理它可能是没有运行时错误,但没有值插入INTEGER。
你也应该删除所有当前的错误处理和处理错误更普遍的方式取代它(并作出code更具体的,如果需要,而不是从一个例子制定的文件):
定义变量IERROR AS INTEGER NO-UNDO。
定义变量cError为字符NO-UNDO。CATCH mySoapErrorObject AS Progress.Lang.SoapFaultError:
DO I误差= 1 TO mySoapErrorObject:NumMessages:
cError = cError + mySoapErrorObject:的getMessage(IERROR)+〜N。
结束。
删除对象mySoapErrorObject。
END CATCH。CATCH mySystemErrorObject AS Progress.Lang.SysError:
DO I误差= 1 TO mySystemErrorObject:NumMessages:
cError = cError + mySystemErrorObject:的getMessage(IERROR)+〜N。
结束。
删除对象mySystemErrorObject。
END CATCH。
和插入在finally块:
如果cError<> 那DO:
MESSAGE错误发生:SKIP
cError
VIEW-ALERT AS-BOX错误。
结束。
I'm trying to update our stocks thought the Magento API using Progress 4GL (OpenEdge 10.2B)
So far so good, ie: I can update the stock if the SKU is a match. But if it isn't, it doesn't return an error.
So I looked into how ABL manages SAOP fault errors, and found some examples which I tried to implement. But to no avail.
My new code is as follows:
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.
In those API's I've worked with SOAP errors only occur when there's a "bigger" error. For instance if the webservice is down, login criteria isn't met, datatypes are wrong etc. Usually a return value is rather in the response and not in the SOAP-envelope.
Could it be that it's simply OK to set a non existent product to inventory 0? What happens if you try to set it to 1? Perhaps you should double check from PHP (or whatever language you usually work with) that the web service actually provides the code you expect in this case?
Otherwise you should look at the wsdl-documentation created - are you 100% sure that the result-parameter (resultado in you code) is an INTEGER and not any form of more complicated xml-document (an object basically)? If it's really a HANDLE it might be that there's no run time error but no value is inserted into the INTEGER.
Also you should remove all your current error handling and replace it with a more general way to handle errors (and make that code more specific if needed rather than working from an example out of the documentation):
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.
And insert in the FINALLY-block:
IF cError <> "" THEN DO:
MESSAGE "Errors occured:" SKIP
cError
VIEW-AS ALERT-BOX ERROR.
END.
这篇关于进展4GL Web服务过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!