1

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_d0823E1C21F1A334DSE0001555D658D08/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;
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Paul
  • 429
  • 1
  • 5
  • 15
  • 1
    where are you calling the webmethod in webservice? – A G May 31 '11 at 14:22
  • Where is the command to save the order? I'm looking for the code that make the save action. – Nelson Miranda May 31 '11 at 14:25
  • Isn't the webmethod only used when building web services? I'm not trying to build one, I'm trying to use a web service that someone else built. I created a proxy for their web service and I call that proxys namespace at the top of the page. using sapWebService; – Paul May 31 '11 at 14:31
  • I think the method, "Bapiret2" is supposed to save it. That's what i was told anyway. – Paul May 31 '11 at 14:32
  • WebServices have methods that are exposed via HTTP in general. Bapiret2() is not a method, its a class. – A G May 31 '11 at 14:36
  • I think something is missing here cause as far I can see you are instancing "Bapiret2" but nothing is sent to it as a parameter or property in first instance to accomplish a transaction. On the other hand it is expected that "Bapiret2" has a web method to make, in this case, an insert. I can see also that the latter instances are just created but there's no place in the code that I can see that does something with them. The question is "where is the web method that "saves" or handle this transactions?" – Nelson Miranda May 31 '11 at 17:44

3 Answers3

2

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);
Paul
  • 429
  • 1
  • 5
  • 15
0

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

PATRY Guillaume
  • 4,287
  • 1
  • 32
  • 41
0

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.

Dirk Trilsbeek
  • 5,873
  • 2
  • 25
  • 23