2011-05-31 83 views
1

我正在開發一個Web服務,它將使用.NET在SAP中創建訂單。現在,當我運行下面的代碼時,我沒有收到任何錯誤,也沒有創建訂單。我希望有人能幫忙。SAP Web服務

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; 
+1

你在哪裏調用web服務中的webmethod? – 2011-05-31 14:22:32

+0

保存訂單的命令在哪裏?我正在尋找進行保存操作的代碼。 – 2011-05-31 14:25:00

+0

是否僅在構建Web服務時使用webmethod?我並沒有試圖建立一個,我試圖使用別人構建的Web服務。我爲他們的web服務創建了一個代理,並且我在頁面頂部調用了這個proxys命名空間。 using sapWebService; – Paul 2011-05-31 14:31:39

回答

2

問題是我需要構建一個數組並將其插入到對象中。見下文。

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; 

我還需要將zSalesOrderCreate對象綁定回Z_SALESORDER_CREATE方法。

ZSalesorderCreateResponse res = createOrder.ZSalesorderCreate(newOrder); 
0

雖然我不是.Net的專家,但在這裏有一些東西。 BapiRet2不是一種方法,而是一個類,並且R/3中有一個同名的結構,通常用於獲取有關函數調用執行的信息...

我認爲你只是創建將/應該包含你的web服務的答案,因爲你不叫後的變量,變量是空的...因此空的錯誤信息......

問候

0

沒有收到消息,因爲你永遠不會致電該服務。代理類Z_SALESORDER_CREATE應該有一個名稱相同或幾乎相同的方法,該方法實際上調用該服務。 BAPIRET2只是一個包含來自服務的返回消息的結構。準備您的呼叫參數,使用這些參數調用服務方法,然後檢查結果的BAPIRET2結構。