Èç¹ûÊÇÍⲿÊÂÎñ£¬ÔòÐèÒª´«µÝADO.Connection¶ÔÏ󣬲¢½«IsIndependenceTransactionÉèÖÃΪtrue£º
envContext.BizDbConnection = new ADO.Connection(); envContext.IsIndependenceTransaction = true;
3£® ÉèÖÃAPIµØÖ·±êʶ(Url)²ÎÊý
//È統ǰAPI¡°ÐÂÔö»òÐ޸ġ±µÄµØÖ·±êʶΪ£ºU8API/SaleOrder/Save
U8ApiAddress myApiAddress = new U8ApiAddress(\
4£® ¹¹ÔìAPIBroker
U8ApiBroker broker = new U8ApiBroker(myApiAddress, envContext);
5£® API¶ÔÏó²ÎÊý¸³Öµ
1) ¸øBO±íÍ·²ÎÊýDomHeadºÍ±íÌå²ÎÊýdomBody¸³ÖµÓÐÁ½ÖÖ·½·¨£¬ÈçÏ£º ·½·¨Ò»ÊÇÖ±½Ó´«ÈëMSXML2.DOMDocumentClass¶ÔÏ󣬴úÂëÈçÏÂ
MSXML2.DOMDocumentClass domHead = new MSXML2.DOMDocumentClass(); domHead.load(\);
broker.AssignNormalValue(\, domHead);
·½·¨¶þÊǹ¹ÔìBusinessObject¶ÔÏ󣬾ßÌå·½·¨ÈçÏ£º
//Ê×ÏÈͨ¹ýGetBoParam·½·¨»ñÈ¡±íÍ·±íÌå²ÎÊý
×¢Ò⣺ÉèÖÃÐÐÊýΪij¸öÖµ£¬ÐÐÊý²¢²»ÏÞ¶¨Îª¸Ã×î´óÖµ£¬¿ÉÒÔһֱ˳ÐòÌí¼ÓÖÁÈÎÒâÐУ¬µ«ÓÐÒ»¸ö¹æÔò£ºÀýÈçµ±ÉèÖÃΪ10ʱ£¬¿ÉÒÔ¶ÔµÚ0¡¢1¡¢??9Ðи³Öµ£¬µ±¶ÔµÚ10Ðи³ÖµÊ±ºò£¬Ôò»á˳ÐòÌí¼ÓÒ»¸öÐÂÐУ¬µ«´ËʱÊDz»ÄܶԵÚ11Ðи³ÖµµÄ£¬µ±Ìí¼ÓÒ»¸öÐÂÐУ¨µÚ10ÐУ©ºó£¬ÓÖ¿ÉÒÔ¶ÔµÚ11ÐнøÐи³Öµ¡£
/****************************** ÒÔÏÂÊDZØÊä×ֶΠ****************************/ domHead[0][\Ö÷¹Ø¼ü×ֶΣ¬intÀàÐÍ domHead[0][\¶© µ¥ ºÅ£¬stringÀàÐÍ domHead[0][\¶©µ¥ÈÕÆÚ£¬DateTimeÀàÐÍ domHead[0][\ÒµÎñÀàÐÍ£¬stringÀàÐÍ ??
/***************************** ÒÔÏÂÊǷDZØÊä×ֶΠ****************************/ domHead[0][\ÏÖ´æ¼þÊý£¬doubleÀàÐÍ BusinessObject DomHead = broker.GetBoParam(\DomHead.RowCount = 10; //ÉèÖÃÐÐÊý
//ÆäÖУ¬¸øBO¶ÔÏóµÄ×ֶθ³Öµ£¬Öµ¿ÉÒÔÊÇÕæʵÀàÐÍ£¬Ò²¿ÉÒÔÊÇÎÞÀàÐÍ×Ö·û´® //ÒÔÏ´úÂëʾÀýÖ»ÉèÖõÚÒ»ÐÐÖµ¡£¸÷×ֶζ¨ÒåÏê¼ûAPI·þÎñ½Ó¿Ú¶¨Òå
domHead[0][\¿ÉÓüþÊý£¬doubleÀàÐÍ domHead[0][\Ô¤·¢»õÈÕÆÚ£¬DateTimeÀàÐÍ domHead[0][\Ô¤Í깤ÈÕÆÚ£¬DateTimeÀàÐÍ domHead[0][\Ô¤·¢»õÈÕÆÚ£¬DateTimeÀàÐÍ
??
2) ¸øÆÕͨ²ÎÊý¸³Öµ ÀýÈ磬
//¸øÆÕͨ²ÎÊýVoucherState£¨²ÎÊýÃû£©¸³Öµ¡£´Ë²ÎÊýµÄÊý¾ÝÀàÐÍΪint£¬´Ë²ÎÊý°´Öµ´«µÝ£¬¾ßÌåÇë²Î¿¼·þÎñ½Ó¿Ú¶¨Òå
broker.AssignNormalValue(\ ×¢Ò⣺ËùÓвÎÊýÃû²»ÏÞ´óСд¡£
3) ¸ø¡°OUTÐÍ¡±²ÎÊý¸³Öµ
Ϊ·½±ãÓû§Ê¹ÓÃU8API£¬Èç¹û²ÎÊýÊý¾ÝÀàÐÍΪһ°ãÖµÀàÐÍ£¬ÈçString¡¢Integer¡¢Long¡¢Single¡¢Double¡¢Boolean¡¢Date£¬Ôò²»±Ø´«ÈëÒ»¸ö²ÎÊý±äÁ¿£¨´«ÈëÒ²¿É£©£»·ñÔò£¬Ôò±ØÐëÒ»¸ö²ÎÊý±äÁ¿¡£
È磺 ??
//¸Ã²ÎÊýcurIDΪOUTÐͲÎÊý£¬ÓÉÓÚÆäÊý¾ÝÀàÐÍΪstring£¬ÎªÒ»°ãÖµÀàÐÍ£¬Òò´Ë²»±Ø´«ÈëÒ»¸ö²ÎÊý±äÁ¿¡£ÔÚAPIµ÷Ó÷µ»Øʱ£¬¿ÉÒÔͨ¹ýGetResult(\»ñÈ¡ÆäÖµ
//¸Ã²ÎÊýCurDomΪOUTÐͲÎÊý£¬ÓÉÓÚÆäÊý¾ÝÀàÐÍΪMSXML2.IXMLDOMDocument2£¬·ÇÒ»°ãÖµÀàÐÍ£¬Òò´Ë±Ø
Ðë´«ÈëÒ»¸ö²ÎÊý±äÁ¿¡£ÔÚAPIµ÷Ó÷µ»Øʱ£¬¿ÉÒÔÖ±½ÓʹÓøòÎÊý
MSXML2.IXMLDOMDocument2 CurDom = new MSXML2.IXMLDOMDocument2(); broker.AssignNormalValue(\
??
µ±²»´«ÈëÒ»¸ö²ÎÊý±äÁ¿Ê±£¬ÔÚAPIµ÷Ó÷µ»Øʱ£¬¿ÉÒÔͨ¹ýGetResult(²ÎÊýÃû)»ñÈ¡ÆäÖµ£»µ±²»±Ø´«ÈëÒ»¸ö²ÎÊý±äÁ¿Ê±£¬ÔÚAPIµ÷Ó÷µ»Øʱ£¬¿ÉÒÔÖ±½ÓÒýÓøòÎÊý¡£
4) ¸ø¡°INOUTÐÍ¡±²ÎÊý¸³Öµ ¶Ô¡°INOUTÐÍ¡±ÐͲÎÊý£¬Ôò²»ÂÛÊÇ·ñÊÇÒ»°ãÖµÀàÐÍ£¬¶¼ÐèÒª´«Èë²ÎÊý±äÁ¿¡£ÆäËûÓë¡°OUTÐÍ¡±²ÎÊýÒ»Ñù¡£
6£® µ÷ÓÃAPI
//ʾÀýµ÷ÓÃÈçÏ£º
if (!broker.Invoke())
{
//´íÎó´¦Àí
Exception apiEx = broker.GetException(); if (apiEx != null) {
if (apiEx is MomSysException)
}
}
{ }
else if (apiEx is MomBizException) { }
MomBizException bizEx = apiEx as MomBizException; Console.WriteLine(\Òì³££º\//todo:Òì³£´¦Àí
MomSysException sysEx = apiEx as MomSysException; Console.WriteLine(\ϵͳÒì³££º\//todo:Òì³£´¦Àí
//½áÊø±¾´Îµ÷Óã¬ÊÍ·ÅAPI×ÊÔ´ broker.Release(); return;
×¢Ò⣺¶Ôµ÷ÓÃʧ°Ü£¬¿ÉÒÔ»ñÈ¡³ö´íÐÅÏ¢£¬Èç¹ûÊÇAPI¿ò¼ÜµÄÔÒò£¬Ôò±¨¸æMomSysExceptionÒì³££¬Èç¹ûÊÇÒµÎñ×é¼þµÄÔÒò£¬Ôò±¨¸æMomBizExceptionÒì³£¡£
7£® »ñÈ¡·µ»Ø½á¹û
1) »ñÈ¡BO¶ÔÏó
ÔÚ¡°×°Ôص¥¾Ý¡±Ê±£¬Í¨¹ýGetBoParam·½·¨»ñÈ¡±íÍ·»ò±íÌå²ÎÊý
BusinessObject DomHeadRet = broker.GetBoParam(\
Console.WriteLine(\¶ÔÏóÐÐÊýΪ£º\»ñÈ¡BO¶ÔÏóµÄÐÐÊý Èç¹ûҪȡÔʼµÄXMLDOM¶ÔÏó½á¹û£¬ÇëʹÓÃGetResult(\MSXML2.DOMDocument DomHeadRet = broker. GetResult(\ÒÔÉÏ»ñÈ¡µÄÐÐÊýÊÇBO¶ÔÏóµÄʵ¼ÊÐÐÊý¡£
//»ñÈ¡BO¶ÔÏó¸÷×ֶεÄÖµ¡£ÒÔÏ´úÂëʾÀýֻȡµÚÒ»ÐС£×ֶζ¨ÒåÏê¼ûAPI·þÎñ½Ó¿Ú¶¨Òå
/****************************** ÒÔÏÂÊDZØÊä×ֶΠ****************************/ int id = Convert.ToInt32(domHeadRet[0][\Ö÷¹Ø¼ü×ֶΣ¬intÀàÐÍ
string ccode = Convert.ToString(domHeadRet[0][\µ¥¾ÝºÅ£¬stringÀàÐÍ DateTime ddate = Convert.ToDateTime(domHeadRet[0][\ÈÕÆÚ£¬DateTimeÀàÐÍ string cbustype = Convert.ToString(domHeadRet[0][\ÒµÎñÀàÐÍ£¬stringÀàÐÍ ??
/***************************** ÒÔÏÂÊǷDZØÊä×ֶΠ****************************/ string cpayname = Convert.ToString(domHeadRet[0][\¸¶¿îÌõ¼þ£¬stringÀàÐÍ string cpersonname = Convert.ToString(domHeadRet[0][\Òµ Îñ Ô±£¬stringÀàÐÍ double itaxrate = Convert.ToDouble(domHeadRet[0][\Ë°ÂÊ£¬doubleÀàÐÍ string cexch_name = Convert.ToString(domHeadRet[0][\±ÒÖÖ£¬stringÀàÐÍ ??
×¢Ò⣺
2)
»ñÈ¡ÆÕͨ·µ»ØÖµ
´úÂëÈçÏ£º
//»ñÈ¡ÆÕͨ·µ»ØÖµ¡£´Ë·µ»ØÖµÊý¾ÝÀàÐÍΪSystem.String£¬´Ë²ÎÊý°´Öµ´«µÝ£¬¾ßÌåÇë²Î¿¼·þÎñ½Ó¿Ú¶¨Òå System.String result = broker.GetReturnValue() as System.String; 3)
»ñÈ¡ÆÕͨ¡°OUTÐÍ¡±»ò¡°INOUTÐÍ¡±·µ»ØÖµ
ÈçÇ°ËùÊö£¬¶ÔÆÕͨ¡°OUTÐÍ¡±»ò¡°INOUTÐÍ¡±²ÎÊý£¬Èç¹ûÊÇÒ»°ãÖµÀàÐÍ£¬Ôòͨ¹ýGetResult·½·¨»ñÈ¡Æä·µ»ØÖµ£¬·ñÔòÖ±½ÓʹÓøÃÒýÓá£
È磬
//»ñÈ¡ÆÕͨOUT²ÎÊýcurID¡£´Ë·µ»ØÖµÊý¾ÝÀàÐÍΪstring£¬ÔÚʹÓøòÎÊý֮ǰ£¬ÇëÅжÏÊÇ·ñΪ¿Õ string curIDRet = broker.GetResult(\
//»ñÈ¡ÆÕͨOUT²ÎÊýCurDom¡£´Ë·µ»ØÖµÊý¾ÝÀàÐÍΪMSXML2.IXMLDOMDocument2£¬Ç°ÃæÒѶ¨Òå¸Ã²ÎÊý£¬ÇëÖ±½ÓʹÓà ??