Click here to Skip to main content
15,884,388 members
Articles / Web Development / ASP.NET

Workflow Service 4.0 is a Major Change: Call WCF Service from Workflow Service 4.0

Rate me:
Please Sign up or sign in to vote.
2.60/5 (4 votes)
7 Nov 2010CPOL4 min read 41.7K   1.2K   16  
New changes and features in Workflow service 4.0 provided with a sample solution to invoke WCF service from workflow service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BSi.Oscar.Contract;


namespace BSi.Oscar.SAPAdapterService
{
    /// <summary>
    /// This class is used to make SAP service call to Create or verify member's credit information in SAP System.
    /// </summary>
    public class SAPOrderManager
    {
        string responseXML = string.Empty;
        /// <summary>
        /// This method is used to verify member's credit in SAP system
        /// </summary>
        /// <param name="basket"></param>
        /// <returns></returns>
        public string VerifyCredit(Basket basketData)
        {
            try
            {
               
                SAPCreateOrderService.ZOSC_BAPI_SALESORDER_CREATEService orderService = new SAPCreateOrderService.ZOSC_BAPI_SALESORDER_CREATEService();
                orderService.Credentials = SAPConfig.GetWebServiceCredential();
                orderService.Url = SAPConfig.GetWebServiceURL();
                BAPIData orderData = GetBAPIdata(basketData);
                responseXML = orderService.ZOSC_BAPI_SALESORDER_CREATE(ref orderData.BAPIBTSEL, null, null, ref orderData.BAPISDBUSI, null, ref orderData.BAPICOND, null, ref orderData.BAPIPAREX, ref orderData.BAPIPAREX1, ref orderData.BAPIINCOMP,
                                                          null, ref orderData.BAPISDIT, null, ref orderData.BAPIADDR1, ref orderData.BAPISDPART, ref orderData.BAPIRET2, null, ref orderData.BAPICCARD, ref orderData.BAPICUBLB, ref orderData.BAPICUINS,
                                                          ref orderData.BAPICUPRT, ref orderData.BAPICUCFG, ref orderData.BAPICUREF, ref orderData.BAPICUVAL, ref orderData.BAPICUVK, ref orderData.BAPICOND1, ref orderData.BAPICONDX, ref orderData.BAPICTR, ref orderData.BAPICTRX, orderData.BAPISDHD1,
                                                          null, ref orderData.BAPISDITM, ref orderData.BAPISDITMX, ref orderData.VBAP, ref orderData.BAPISDKEY, ref orderData.BAPIPARNR, ref orderData.BAPISCHDL, ref orderData.BAPISCHDLX, ref orderData.BAPISCHDL2, ref orderData.BAPISDTEXT,
                                                          ref orderData.BAPISDHEDU, null, null, orderData.TestRun, ref orderData.BAPISDTEHD, ref orderData.BAPITEXTLI, out orderData.BAPISDHD, out orderData.BAPISDHDST);
            }
            catch (Exception ex)
            {
                throw new Exception("SAP Service error", ex);
            }
            return responseXML;
        }
        /// <summary>
        /// This method is used to Create Order in SAP system
        /// </summary>
        /// <param name="basket"></param>
        /// <returns></returns>
        public string CreateOrder(Basket basketData)
        {           
            try
            {
                SAPCreateOrderService.ZOSC_BAPI_SALESORDER_CREATEService orderService = new SAPCreateOrderService.ZOSC_BAPI_SALESORDER_CREATEService();
                orderService.Credentials = SAPConfig.GetWebServiceCredential();
                orderService.Url = SAPConfig.GetWebServiceURL();
                BAPIData orderData = GetBAPIdata(basketData);
                responseXML = orderService.ZOSC_BAPI_SALESORDER_CREATE(ref orderData.BAPIBTSEL, null, null, ref orderData.BAPISDBUSI, null, ref orderData.BAPICOND, null, ref orderData.BAPIPAREX, ref orderData.BAPIPAREX1, ref orderData.BAPIINCOMP,
                                                          null, ref orderData.BAPISDIT, null, ref orderData.BAPIADDR1, ref orderData.BAPISDPART, ref orderData.BAPIRET2, null, ref orderData.BAPICCARD, ref orderData.BAPICUBLB, ref orderData.BAPICUINS,
                                                          ref orderData.BAPICUPRT, ref orderData.BAPICUCFG, ref orderData.BAPICUREF, ref orderData.BAPICUVAL, ref orderData.BAPICUVK, ref orderData.BAPICOND1, ref orderData.BAPICONDX, ref orderData.BAPICTR, ref orderData.BAPICTRX, orderData.BAPISDHD1,
                                                          null, ref orderData.BAPISDITM, ref orderData.BAPISDITMX, ref orderData.VBAP, ref orderData.BAPISDKEY, ref orderData.BAPIPARNR, ref orderData.BAPISCHDL, ref orderData.BAPISCHDLX, ref orderData.BAPISCHDL2, ref orderData.BAPISDTEXT,
                                                          ref orderData.BAPISDHEDU, null, null, orderData.TestRun, ref orderData.BAPISDTEHD, ref orderData.BAPITEXTLI, out orderData.BAPISDHD, out orderData.BAPISDHDST);
                      
            }
            catch (Exception ex)
            {
                throw new Exception("SAP Service error", ex);
            }
            return responseXML;
        }

        public BAPIData GetBAPIdata(Basket basket)
        {
            BAPIData bapiData = new BAPIData();

            bapiData.TestRun = "X";

            bapiData.BAPISDHD1.DOC_TYPE = basket.DocumentType;
            bapiData.BAPISDHD1.PURCH_NO_C = basket.PurchaseOrderNumber;
            bapiData.BAPISDHD1.ASS_NUMBER = basket.OrderNumber;
            bapiData.BAPISDHD1.SALES_ORG = "2000";
            bapiData.BAPISDHD1.DISTR_CHAN = "50";
            bapiData.BAPISDHD1.DIVISION = "10";
            bapiData.BAPISDHD1.ORD_REASON = "Z31";
            bapiData.BAPISDHD1.CURRENCY = "GBP";

            SAPCreateOrderService.BAPIPARNR partner = new SAPCreateOrderService.BAPIPARNR();
            partner.PARTN_ROLE = "WE";
            partner.ADDRESS = "444";            
            bapiData.BAPIPARNR = new SAPCreateOrderService.BAPIPARNR[1];
            bapiData.BAPIPARNR[0] = partner;
            //foreach (Item itm in basket.Items)
            //{

            //}
            
            return bapiData;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer British Standard Institute (BSi), London
United Kingdom United Kingdom
My passion is

Microsoft distributed and connecting Technologies like Windows Communication foundation (WCF)
Workflow Services (WWF)
ASP.Net MVC and MVVM
JASON
JQuery
SQL Server
Oracle
Optimization in all of these

and more @ http://jetmathew.wordpress.com/

Comments and Discussions