cXML的PunchOutSetupRequest和PunchOutSetupResponse在C#示例 [英] cXML PunchOutSetupRequest and PunchOutSetupResponse examples in C#

查看:541
本文介绍了cXML的PunchOutSetupRequest和PunchOutSetupResponse在C#示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现我们的逸康网站目录样片。老实说,对于cXML的文档是一个烂摊子,所有的代码示例都是在JavaScript和/或VB.Net(我使用C#和宁可不要尝试和翻译)。有没有人在那里有例子或如何接收PunchOutSetupRequest XML样本,然后使用C#送出去的PunchOutSetupResponse XML?我一直无法找到在interwebs任何东西(我一直在寻找两天现在)...

I'm trying to implement punchout catalogs on our eComm site. Honestly, the documentation for cXML is a mess and all the code examples are in javascript and/or VB.Net (I use C# and would rather not have to try and translate). Does anyone out there have examples or samples of how to receive the PunchOutSetupRequest XML and then send out the PunchOutSetupResponse XML using C#? I've been unable to find anything on the interwebs (I've been looking for two days now)...

我希望我可以做这里面一个ActionResult(对比启动页的建议)。

I'm hoping I can just do this inside an ActionResult (vs. a 'launch page' as suggested).

我在穿孔样片一个完整的小白和真的可以在这里使用一些帮助。老板们正在非常爱出风头,所以任何援助将不胜感激。建议如何使这项工作也将非常感激。

I'm a complete noob at punchouts and could really use some help here. The bosses are being pretty pushy, so any assistance would be greatly appreciated. Suggestions as to how to make this work would also be much appreciated.

我道歉,所有的问题(要求)的模糊性。

I apologize to all for the vagueness of the question (request).

推荐答案

这是不平凡的,但这应该让你开始。

This isn't trivial, but this should get you started.

您需要3一般处理程序(ashx的):安装,启动和秩序......

You'll need 3 generic handlers (.ashx): Setup, Start, and Order....

设置和秩序将得到HTTP POST与内容类型为text / XML的。如果需要获取XML转换成字符串看看HttpRequest.InputStream。从那里,看看LINQ到XML挖掘出你想要的数据。您对这两HTTP响应也将是内容类型为text / xml的和UTF8编码,作为返回记录的CXML ...使用LINQ到XML来产生。

Setup and Order will receive HTTP Post with content-type of "text/xml". Look at HttpRequest.InputStream if needed to get the XML into a string. From there, look at LINQ-to-XML to dig out the data you want. Your HTTP Response to both of these will also be content-type "text/xml" and UTF8 encoded, returning the CXML as documented...use LINQ-to-XML to produce that.

安装程序处理程序将需要验证凭据,并以独特的QueryString令牌指向启动处理程序返回的URL。不要指望安装和启动之间的会话持久性,因为他们来自同一个来电者不是。该处理器将需要为您从cXML的提取令牌和相关数据的应用对象。

The Setup handler will need to validate credentials and return a URL with a unique QueryString token pointing to the Start handler. Do not expect session persistence between Setup and Start, because they're not from the same caller. This handler will need to create an application object for the token and associated data you extracted from the cXML.

在开始处理程序将被称为一个简单的GET,并需要以匹配查询字符串到相应的应用程序对象的令牌,将数据复制到会话,然后做一个Response.Redirect的到你想要的买家的土地上无论您的网站的网页。

The Start handler will be called as a simple GET, and will need to match the token in the QueryString to the appropriate application object, copy that data to the session, and then do a response.redirect to whatever page in your site you want the buyer to land on.

一旦填充自己的车有一些东西,并准备退房,你会带他们到具有嵌入表单的页面(不要与一个ASP.Net的形式混淆起来,回发到您的服务器)和一个提交按钮(同样,没有一个ASP.Net按钮)。从您的安装程序处理程序,捕捉一个URL指向这种形式的帖子,并在表单中你必须用UTF8编码CXML穿孔所得订购一个隐藏的输入标记注入与LINQ到XML产生的价值。强烈建议Base64编码的值,以避免与ASP.Net它所包含的标签渲染过程中插科打诨,和命名隐藏的输入每个文档CXML-的base64。其结果是形式为客户端发布到客户的服务器,而不是你的,他们的服务器将提取CXML所得样片订购和结束你的访客的会话。

Once they populate their cart with some things, and are ready to check out, you'll take them to a page that has an embedded form (not to be confused with an ASP.Net form that posts back to your server) and a submit button (again, not an ASP.Net button). From your Setup handler, you captured a URL to point this form's Post, and within the form you'll have a hidden input tag with the UTF8 encoded CXML Punchout Order injected as the value produced with LINQ-to-XML. Highly recommend Base64 encoding that value to avoid ASP.Net messing with the tags it contains during rendering, and naming the hidden input "cxml-base64" per the documentation. The result is the form is client-side POSTed to your customer's server instead of yours, and their server will extract the CXML Punchout Order and that ends your visitor's session.

为了处理程序将收到一个CXML OrderRequest并就像设置,你会转储到一个字符串,然后使用LINQ到XML解析它并呼吁采取行动。同样,你会得到证书验证,可能是信用卡的过程,以及订单的项目,舰等注意OrderRequest可能不包含所有原来在所得样片订购的物品,因为系统上的客户的侧面可以删除项目甚至提交最终OrderRequest你之前更改项目的数量。该OrderRequest的所得样片订购后可以回来给你发布到他们在短短的几分钟,几天,几周,或者从来没有... ...不打扰存储在它匹配后的顺序,希望车的数据。

The Order handler will receive a CXML OrderRequest and just like Setup, you'll dump that to a string and then use LINQ-to-XML to parse it and act upon it. Again you'll get credentials to verify, possibly a credit card to process, and the order items, ship-to, etc. Note that the OrderRequest may not contain all the items that were in the Punchout Order, because the system on your customer's side may remove items or even change item quantities before submitting the final OrderRequest to you. The OrderRequest could come back to you after the Punchout Order is posted to them in a matter of minutes, days, weeks, or never...don't bother storing the cart data in hopes of matching it to the order later.

最后一个音符...买家可能会遇到镶嵌在其基于Web的用户界面采购的iframe您的网站,因此设计相应。

Last note...the buyer may be experiencing your site in an iframe embedded in their web-based procurement UI, so design accordingly.

如果您需要更多信息,请回覆此,我会回来。

If you need more info, reply to this and I'll get back.

更新...其他注意事项:
与讨论他们希望如何故障处理流动,特别是订单,是因为你有一个选择买家。 1)详尽评估收到CXML的一切,并返回200多名其他响应代码如果有什么是错的,或2)始终返回一个200成功和处理任何问题带外或通过产生拒绝的顺序ConfirmationRequest。我的经验是,两者的混合效果最好。当然,你应该抛出一个非200如果凭据失败,但你可能不希望(或能够)运行信用卡或验证的库存内联。买家的系统可能无法应付几十个可能出现的故障和/或可能不会显示你的错的消息给用户为他们改正。我已经看到了将单位出丢弃任何非200响应代码,只是一味地反复重试提交关于数小时或数天的时间间隔,直到它在一个全面的检查放弃,而其他人将在一定范围内处理响应代码不同的系统比其他人,例如4XX调用重试,而5XX作为致命的对待。请记住,安装与秩序并非直接来自用户......他们的采购系统生成的内部。

Update...Additional considerations: Discuss with the buyer how they want fault handling to flow, particularly with orders, because you have a choice. 1) exhaustively evaluate everything in the CXML you receive and return response codes other than 200 if anything is wrong, or 2) always return a 200 Success and deal with any issues out of band or by generating a ConfirmationRequest that rejects the order. My experience is that a mix of the two works best. Certainly you should throw a non-200 if the credentials fail, but you may not want (or be able) to run a credit card or validate stock availability inline. Your buyer's system may not be able to cope with dozens of possible faults, and/or may not show your fault messages to the user for them to make corrections. I've seen systems that will flat-out discard any non-200 response code and just blindly retry the submission repeatedly on an interval for hours or days until it gives up on a sanity check, while others will handle response codes within certain ranges differently than others, for example a 4xx invokes a retry, while a 5xx is treated as fatal. Remember that Setup and Order are not coming directly from the user...their procurement system is generating those internally.

更新...回答有关如何测试的东西留言...

Update...answering the comment about how to test things...

您会使用相同的方法,你会产生出站ConfirmationRequest,ShipNoticeRequest和InvoiceDetailRequest,所有其中,一般都是收到客户的采购系统中OrderRequest后,就在你身边产生的。

You'd use the same method as you will for generating outbound ConfirmationRequest, ShipNoticeRequest, and InvoiceDetailRequest, all of which generally are produced on your side after receiving an OrderRequest from your customer's procurement system.

开始用的 LINQ到XML 以各具特色的传出cXML的(创建XML树节)的一个例子。结合了该位的代码,例如:

Start with Linq-To-XML for an example of crafting your outgoing cXML (Creating XML Trees section). Combine that example with this bit of code:

StringBuilder output = new StringBuilder();

XmlWriterSettings objXmlWriterSettings = new XmlWriterSettings();
objXmlWriterSettings.Indent = true;
objXmlWriterSettings.NewLineChars = Environment.NewLine;
objXmlWriterSettings.NewLineHandling = NewLineHandling.Replace;
objXmlWriterSettings.NewLineOnAttributes = false;
objXmlWriterSettings.Encoding = new UTF8Encoding();

using (XmlWriter objXmlWriter = XmlWriter.Create(output, objXmlWriterSettings)) {
    XElement root = new XElement("Root",
        new XElement("Child", "child content")
    );
    root.Save(objXmlWriter);
}
Console.WriteLine(output.ToString());



所以,在这一点上的StringBuilder(输出)有你的整个cXML的,你需要在某处张贴。您的Web应用程序项目,开始与F5和Default.aspx页面将本地主机和一些端口上监听(你会看到,在URL它打开)。另外,可能使用VS Express的桌面,你有一个控制台应用程序上面的代码可以运行使用像这样做后:

So at this point the StringBuilder (output) has your whole cXML, and you need to POST it someplace. Your Web Application project, started with F5 and a default.aspx page will be listening on localhost and some port (you'll see that in the URL it opens). Separately, perhaps using VS Express for Desktop, you have the above code in a console app that you can run to do the Post using something like this:

Net.HttpWebRequest objRequest = Net.WebRequest.Create("http://localhost:12345/handler.ashx");

objRequest.Method = "POST";
objRequest.UserAgent = "Some User Agent";
objRequest.ContentLength = output.Length;
objRequest.ContentType = "text/xml";

IO.StreamWriter objStreamWriter = new IO.StreamWriter(objRequest.GetRequestStream, System.Text.Encoding.ASCII);
objStreamWriter.Write(output);
objStreamWriter.Flush();
objStreamWriter.Close();

Net.WebResponse objWebResponse = objRequest.GetResponse();
XmlReaderSettings objXmlReaderSettings = new XmlReaderSettings();
objXmlReaderSettings.DtdProcessing = DtdProcessing.Ignore;
XmlReader objXmlReader = XmlReader.Create(objWebResponse.GetResponseStream, objXmlReaderSettings);

// Pipes the stream to a higher level stream reader with the required encoding format.  
IO.MemoryStream objMemoryStream2 = new IO.MemoryStream();
XmlWriter objXmlWriter2 = XmlWriter.Create(objMemoryStream2, objXmlWriterSettings);
objXmlWriter2.WriteNode(objXmlReader, true);
objXmlWriter2.Flush();
objXmlWriter2.Close();
objWebResponse.Close();

// Reset current position to the beginning so we can read all below.
objMemoryStream2.Position = 0;

StreamReader objStreamReader = new StreamReader(objMemoryStream2, Encoding.UTF8);
Console.WriteLine(objStreamReader.ReadToEnd());
objStreamReader.Close();



由于您的处理程序应该产生cXML的,你会看到在控制台吐出来。如果pukes,你会得到调试混乱的控制台,这当然会帮助你解决什么是坏了一个大的blob。

Since your handler should be producing cXML you'll see that spat out in the console. If it pukes, you'll get a big blob of debug mess in the console, which of course will help you fix whatever is broken.


  • 原谅冗长的变量名,做到尽量把事情说清楚。

这篇关于cXML的PunchOutSetupRequest和PunchOutSetupResponse在C#示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆