首页 新闻 会员 周边

求小例子 在asp.net 中如何使用 sap Noc 3.0 调用SAP中的接口

0
悬赏园豆:50 [已解决问题] 解决于 2012-06-21 17:33

ASP.NET中使用 SAP Noc 3.0如何连接SAP; 如何调用SAP中的接口获取到数据。

SAPl连接:

AShost:10.0.3.14

Sysnr:0

Client:800

Language:ZH

User:sa

Passwd:123456
SAP中的接口名:zh_tb_UserInfo()

Sunny九天的主页 Sunny九天 | 初学一级 | 园豆:157
提问于:2012-06-11 15:27
< >
分享
最佳答案
1
View Code
private void SAPConnect()
        {
            /* this routine creates a proxy object, if one doesn't already
             * exist and creates the SAP connection if needed. It's called
             * before each SAP RFC call just in case */

            // create one proxy for all methods
            if (null == proxy)
            {
                proxy = new SAPProxy1();
            }
            if (false == g_IsConnected)
            {
                proxy.Connection =  new SAP.Connector.SAPConnection(this.destination1);    
                try {proxy.Connection.Open();}
                catch (Exception ex)
                {MessageBox.Show("Invalid SAP connection, please fix" + ex.ToString());}
            }                        
        } //SAPConnect()
private void SAPAsyncSearch()
        {
    /* this routine calls RFC_CUSTOMER_GET using .Net asynchronous
     * method invocation. When the function is completed asynchronously in SAP, 
     * the function "myfunction" is called. */
            SAPConnect();
            myAsyncState = null;
            myCallback = new System.AsyncCallback(myFunction);
            asyncresult = null;
            try 
            {
                asyncresult = proxy.BeginRfc_Customer_Get(g_custNo, g_custName, ref brfcknA1Table1, myCallback, myAsyncState);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error returned in Async search\n" + ex.ToString(), "SAP Async Search problem");
                return;
            }
        }

        private void myFunction(IAsyncResult ar)
        {
            /* this function gets called when rfc function is done executing 
             * asynchronously. It reconnects the main form thread to the results */
            MessageBox.Show("async call is returned from SAP", "Asynchronous update status");
            try 
            {
                proxy.EndRfc_Customer_Get(asyncresult, ref brfcknA1Table1);
            }
            catch(Exception ex)
            {
                MessageBox.Show("Exception occurred in async callback \n" + ex.ToString());
                return;
            }
            finally 
            {
                proxy.Connection.Close();
                g_IsConnected = false;
            }
            
            if (0 < brfcknA1Table1.Count)
            {
                SetShowAllMenu(this.mainMenu1);
            }
                        
        } // myfunction

        private void SAPTableToXML()
        {
            /* this routine saves the SAP table from RFC_CUSTOMER_GET
             * into an XML file. It uses the save dialog control to ask the 
             * user what file to save to. It creates the xml file by serializing the SAP Table (BRFCKna1Table) */
            
            // Use save dialog box to get the file to save into
            saveFileDialog1.ShowDialog();
            string file = saveFileDialog1.FileName; 
            
            // serialize to xml 
            XmlSerializer xs = new XmlSerializer(typeof(BRFCKNA1Table));
            System.Text.Encoding unicode = new System.Text.UnicodeEncoding();
            XmlTextWriter xtw = new XmlTextWriter(file, unicode);
            xs.Serialize(xtw, brfcknA1Table1);
            xtw.Close();
        
        } //SAPTableToXML

        private void ShowCustSelect()
        {
            /* this form gets the RFC_CUSTOMER_GET input
             * criteria. The criteria are Name and/or customer No. We need these values 
             * before calling the RFC.
             */

            // show a dialog box to enter customer search selections 
            frmCustomerSelection fc = new frmCustomerSelection(g_custNo, g_custName);
            fc.ShowDialog(this);

            // save the results to my variables for later use
            if (null != fc.Cust)
            {
                g_custName = fc.Cust.CustName;
                g_custNo = fc.Cust.CustNo;
                // we have selections now but not data so update menu status
                SetNoDataMenu();
                this.statusBar1.Text = "Customer selection: Name: " + g_custName + " number: " + g_custNo;
            }
        } //showCustSelec

http://www.itpub.net/thread-936771-1-1.html

http://www.codeproject.com/Articles/24161/Using-the-SAP-NET-Connector-to-Connect-your-NET-Ap

收获园豆:25
悟行 | 专家六级 |园豆:12559 | 2012-06-11 16:40

高手 很感谢你贴了这么长的代码上来

能不能把连接Nco3.0连接SAP,与调用SAP接口的返回数据的代码考给我下

Sunny九天 | 园豆:157 (初学一级) | 2012-06-11 16:50
其他回答(1)
0

http://www.cnblogs.com/mengxin523/category/315696.html

这里有一个比较前面的介绍,我也做过asp.net访问sap的进站和出站,如果你在做的过程中有问题,再继续讨论了。

收获园豆:25
水晶途途 | 园豆:1443 (小虾三级) | 2012-06-12 10:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册