在 ASP.NET 中使用 SAP Web 服务失败

发布于 2024-11-11 13:51:05 字数 2883 浏览 3 评论 0原文

我正在开发一个 Web 服务,该服务将使用 .NET 在 SAP 中创建订单。现在,当我运行下面的代码时,我没有收到任何错误,也没有创建订单。我希望有人能提供帮助。

    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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天旳寂寞 2024-11-18 13:51:05

问题是我需要构建一个数组并将其插入到对象中。见下文。

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);

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);
-柠檬树下少年和吉他 2024-11-18 13:51:05

虽然我不是 .Net 方面的专家,但这里有一些奇怪的事情。 BapiRet2 不是一个方法,而是一个类,并且 R/3 中有一个同名的结构,通常用于获取有关函数调用执行的信息...

我认为您只是创建了一个变量,该变量将/ 应该包含您的网络服务的答案,并且由于您不调用后者,因此该变量为空...因此空的错误消息...

考虑

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

回忆躺在深渊里 2024-11-18 13:51:05

您没有收到任何消息,因为您从未致电该服务。代理类 Z_SALESORDER_CREATE 应该有一个具有相同或几乎相同名称的方法,该方法实际上调用服务。 BAPIRET2 只是一个包含服务返回消息的结构。准备调用参数,使用这些参数调用服务方法,然后检查 BAPIRET2 结构以获取结果。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文