开发者

Consuming SAP Web Service in ASP.NET fails

开发者 https://www.devze.com 2023-03-09 06:11 出处:网络
I\'m working on a web service that will create orders in SAP using .NET. Right now when I run the code below, I receive no errors and no order is created. I was hoping someone could help.

I'm working on a web service that will create orders in SAP using .NET. Right now when I run the code below, I receive no errors and no order is created. I was hoping someone could help.

    string message = "";

    // create initial connection
    Z_SALESORDER_CREATE createOrder = new Z_SALESORDER_CREATE();

    try
    {
        NetworkCredential cred = new NetworkCredential("password", "username");

        createOrder.Url = "http://saphost:8010/sap/bc/srt/wsdl/bndg_d0823E开发者_Go百科1C21F1A334DSE0001555D658D08/wsdl11/allinone/ws_policy/document?sap-client=110";
        createOrder.Credentials = cred;
    }
    catch (Exception ex){
        message = "An error occured." + ex.Message;
    }


    // ORDERS_HEADER_IN
    Bapisdhd1 order_header_in = new Bapisdhd1();
    order_header_in.DocType = "OR";
    order_header_in.CollectNo = "1109512";
    order_header_in.SalesOrg = "10090";
    order_header_in.DistrChan = "100";
    order_header_in.Division = "000";
    order_header_in.DlvBlock = "020";
    order_header_in.PurchNoC = "E-COMM ORDER TEST ORDER";

    // ORDER_ITEMS_IN
    Bapisditm order_items_in = new Bapisditm();
    order_items_in.ItmNumber = "198295";
    order_items_in.Material = "454659";
    order_items_in.GrossWght = 0.003M;
    order_items_in.NetWeight = 0.003M;
    order_items_in.UntofWght = "KG";

    Bapisditm order_items_in2 = new Bapisditm();
    order_items_in2.ItmNumber = "198425";
    order_items_in2.Material = "454664";
    order_items_in2.GrossWght = 0.003M;
    order_items_in2.NetWeight = 0.003M;
    order_items_in2.UntofWght = "KG";

    Bapisditm order_items_in3 = new Bapisditm();
    order_items_in3.ItmNumber = "198725";
    order_items_in3.Material = "454647";
    order_items_in3.GrossWght = 0.003M;
    order_items_in3.NetWeight = 0.003M;
    order_items_in3.UntofWght = "KG";

    Bapisditm order_items_in4 = new Bapisditm();
    order_items_in4.ItmNumber = "198275";
    order_items_in4.Material = "45696INK";
    order_items_in4.GrossWght = 0.003M;
    order_items_in4.NetWeight = 0.003M;
    order_items_in4.UntofWght = "KG";

    // ORDER_PARTNERS
    Bapiparnr order_partners = new Bapiparnr();
    order_partners.PartnRole = "SP";
    order_partners.PartnNumb = "110512";

    order_partners.PartnRole = "BP";
    order_partners.PartnNumb = "110512";

    order_partners.PartnRole = "PY";
    order_partners.PartnNumb = "110512";

    order_partners.PartnRole = "SH";
    order_partners.PartnNumb = "120109";

    Bapicond order_conditions = new Bapicond();
    order_conditions.ItmNumber = "000010";
    order_conditions.CondStNo = "013";
    order_conditions.CondCount = "01";
    order_conditions.CondType = "ZPRM";
    order_conditions.CondValue = 1;
    order_conditions.Currency = "USD";

    // commit transation
    Bapiret2 commit = new Bapiret2();
    message += commit.Message + commit.MessageV1 + commit.MessageV2 + commit.MessageV3 + commit.MessageV4 + commit.LogMsgNo + commit.LogNo;


The issue is that I needed to build an array and insert it into the object. See Below.

Bapisdhd1 order_header_in = new Bapisdhd1();
order_header_in.DocType = "OR";
order_header_in.CollectNo = "1109512";
order_header_in.SalesOrg = "10090";
order_header_in.DistrChan = "100";
order_header_in.Division = "000";
order_header_in.DlvBlock = "020";
order_header_in.PurchNoC = "E-COMM ORDER TEST ORDER";
newOrder.OrderHeaderIn = order_header_in;

I also needed something to tie the zSalesOrderCreate object back to the Z_SALESORDER_CREATE method.

    ZSalesorderCreateResponse res = createOrder.ZSalesorderCreate(newOrder);


While i'm not an expert in .Net, there is something stange here. BapiRet2 is not a method, but a class, and there is a structure with the same name in R/3 that is commonly used to get information on the execution of functions calls...

i think you're just creating the variable that will/should contain the answer of your webservice, and since you don't call the later, the variable is empty... thus the empty error message...

regards


You receive no message because you never call the service. The proxy class Z_SALESORDER_CREATE should have a method with the same or almost the same name, that method actually calls the service. BAPIRET2 is only a structure that contains the return messages from the service. Prepare your call parameters, call the service method with these parameters and then check the BAPIRET2-structure for the results.

0

精彩评论

暂无评论...
验证码 换一张
取 消