Solved

Amazon CXML post and retrival in ASP

Posted on 2008-10-09
23
2,402 Views
Last Modified: 2010-05-18
I have been working on this all day and have reached a dead end. I am trying to send an order to Amazon via a CXML OrderRequest Post and then retreive the CXML Response using ASP. Does anyone have a sample of a ASP CXML post and read with Amazon?  I have have not even been able to Post alone read the return Response. The closet I have gotton is  "Bad Request:Must specify cXML dtd version (1.2.010 - 1.2.019) in DOCTYPE of XML Header".


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd">
<cXML xml:lang="en-US" timestamp="2008-10-09T18:25:49-07:00" payloadID="9992686398467498529@bizrewards.biz">
0
Comment
Question by:apheggie
  • 13
  • 6
  • 3
23 Comments
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
I have ASP.NET code to receive cXML documents and return a cXML response and have .NET code to send cXML Order Requests and receive cXML response messages.  Are you stuck in ASP or can you use .NET?
0
 

Author Comment

by:apheggie
Comment Utility
I guess I can write it in .net. Are you working with the Amazon interface.? Their doc in very vague.
0
 

Author Comment

by:apheggie
Comment Utility
Sorry for odd  first response. I was up to 3:00AM fighting this code. I would LOVE to have your help!
0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
apheggie,

Here is some sample code that I have built in ASP.NET 1.1 that receives cXML documents from a third party.  The first portion of the code is the code behind code that backs the ASP.NET webform that the thirdparty points to when the post a new cXML document to us.

There is another portion of code that is a helper method that I use to build a cXML response that I send back to them (success or failure).

Let me know if this helps.
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Drawing;

using System.IO;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Xml;
 

namespace CompanyName.eCommerce

{

	/// <summary>

	/// Summary description for WebForm1.

	/// </summary>

	public class Default : System.Web.UI.Page

	{
 

		#region Web Form Designer generated code

		override protected void OnInit(EventArgs e)

		{

			//

			// CODEGEN: This call is required by the ASP.NET Web Form Designer.

			//

			InitializeComponent();

			base.OnInit(e);

		}

		

		/// <summary>

		/// Required method for Designer support - do not modify

		/// the contents of this method with the code editor.

		/// </summary>

		private void InitializeComponent()

		{    

			this.Load += new System.EventHandler(this.Page_Load);

		}

		#endregion
 

		private void Page_Load(object sender, System.EventArgs e)

		{

			try

			{

				//http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/073b328fa7cdebec?hl=en&

				// Create a Stream object to capture entire InputStream from browser.

				Stream str = Request.InputStream;
 

				// Find number of bytes in stream.

				int strLen = (int)str.Length;
 

				if(strLen>0)

				{
 

					Response.ContentType = "text/xml";
 

					// Create a byte array to hold stream.

					byte[] bArr = new byte[strLen];
 

					// Read stream into byte array.

					str.Read(bArr,0,strLen);
 

					// Convert byte array to a text string.

					String strmContents="";

					for(int i = 0; i < strLen; i++)

					{

						strmContents = strmContents + (Char)bArr[i];

					}
 

					// write string into a file using filestream

					string Filepath = Path.Combine(Server.MapPath("."), Guid.NewGuid().ToString() + ".xml");

					FileStream fs = new	FileStream(Filepath,FileMode.CreateNew,FileAccess.Write);

					StreamWriter sw = new StreamWriter(fs);

					sw.Write(strmContents);

					sw.Flush();

					sw.Close();
 

					cXMLHelper.prepareXmlResponse(Response, true);
 

					LogManager.WriteEntry("eProcurement", string.Format("{0} file received successfully.", Filepath), EventLogEntryType.Information);

				}

				else

				{

					cXMLHelper.prepareXmlResponse(Response, false);

				}

			}

			catch(Exception ex)

			{

				System.Diagnostics.Debug.WriteLine(ex);

				cXMLHelper.prepareXmlResponse(Response, false);

				LogManager.WriteEntry("eProcurement", string.Format("File receive failed\n\n{0}.", ex.ToString()), EventLogEntryType.Error);

			}

		}
 

	}

}
 
 

===============================================
 

using System;

using System.Xml;

using System.Web;

using System.Globalization;
 

namespace CompanyName.eCommerce

{

	/// <summary>

	/// Summary description for cXMLHelper.

	/// </summary>

	public class cXMLHelper

	{

		private cXMLHelper()

		{

		}
 

		//TODO: generate the timestamp

		internal static void prepareXmlResponse(HttpResponse response, bool success)

		{

			XmlTextWriter xmlResponse = new XmlTextWriter(response.OutputStream, System.Text.Encoding.UTF8);
 

			xmlResponse.Formatting = Formatting.Indented;
 

			xmlResponse.WriteStartDocument();

			xmlResponse.WriteDocType("cXML", null, "http://xml.cxml.org/schemas/cXML/1.1.006/cXML.dtd", null);

			xmlResponse.WriteStartElement("cXML");

			xmlResponse.WriteAttributeString("version", "1.0");

			xmlResponse.WriteAttributeString("payloadID", "123");

			xmlResponse.WriteAttributeString("timestamp", GetFormattedDateTimeString(DateTime.Now));
 

			xmlResponse.WriteStartElement("Response");
 

			xmlResponse.WriteStartElement("Status");
 

			if(success)

			{

				xmlResponse.WriteAttributeString("code", "200");

				xmlResponse.WriteAttributeString("text", "success");

			}

			else

			{

				xmlResponse.WriteAttributeString("code", "500");

				xmlResponse.WriteAttributeString("text", "failure");

			}
 

			xmlResponse.WriteEndElement(); // Status

			xmlResponse.WriteEndElement(); // Response

			xmlResponse.WriteEndElement(); // cXML

			xmlResponse.WriteEndDocument();

			xmlResponse.Flush();

			xmlResponse.Close();

		}
 

		internal static string GetFormattedDateTimeString(DateTime dt)

		{

			// For details on this formatting. see: http://www.w3.org/TR/NOTE-datetime
 

			// .NET info on DateTimeFormatInfo Class:

			// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp

			return dt.ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture);

		}
 

	}

}

Open in new window

0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
apheggie, I have included some code that I use in a .NET 1.1 Windows Forms app to post a cXML Order Requests to a partner and receive the cXML response back.  There is some code/logic you don't need but I left in there.  Not the sexiest code but it has been working well for us.  Hope this helps,

Please provide the link to Amazon's documentation on posting a cXML document to their system.  I am curious to learn more about their platform.

Cheers,
public static string SendRequest(string url, string request)

{

	HttpWebRequest req = null;

	HttpWebResponse resp = null;

	Stream reqStream = null;
 

	try

	{

		UTF8Encoding enc = new UTF8Encoding();

		byte [] data = enc.GetBytes(request);

	

		req = (HttpWebRequest)WebRequest.Create(url);

		req.Method				= "POST";

		req.ContentLength		= data.Length;

		req.ContentType			= "text/xml";

		req.Proxy = System.Net.WebProxy.GetDefaultProxy();

		req.AllowAutoRedirect = true;
 

		// this didn't seem to make any difference

		req.ProtocolVersion = HttpVersion.Version10;

		req.KeepAlive			= false;

		req.AllowWriteStreamBuffering = true;
 

		

		// tried setting these different timeouts with no real improvement

		//req.Timeout				= 60000;

		req.ReadWriteTimeout	= 60000;

		req.ServicePoint.MaxIdleTime = 100000;

		

		reqStream = req.GetRequestStream();

		reqStream.Write(data, 0, data.Length);

		

		resp = (HttpWebResponse)req.GetResponse();

		if (req.HaveResponse)

		{

			if (resp.StatusCode == HttpStatusCode.OK || resp.StatusCode == HttpStatusCode.Accepted)

			{

				StreamReader reader = new StreamReader(resp.GetResponseStream());

				return reader.ReadToEnd();

			}

			else

			{

				throw new Exception("Request failed: " + resp.StatusDescription);

			}

			

		}

		return null;

	}

	finally

	{

		if(req!=null)

		{

			req = null;

		}

		if(resp!=null)

			resp.Close();

		if(reqStream!=null)

			reqStream.Close();

	}

}
 

========================================

// apheggie, here is the code that calls the SendRequest method listed above.

// It takes the URL to post to and an XML string that represents the cXML document.

// note, there are thigs that I do here that you would eliminate, logging, etc.
 

// ... more logic above omitted for simplicity's sake

// validation result is an object that I use to record lots of status

// messages and status states thoughout a log involved workflow; you don't need

// this but I left it here so you could see how I track the progress of this entire system

ValidationResult result = new ValidationResult();

// ...more logic below omitted for simplicity's sake
 
 

// get the post URL

string url = ConfigurationSettings.AppSettings["Request.URL"];

string request = "";

string response = "";

XmlDocument doc = new XmlDocument();

doc.Load(fileName);

request = doc.OuterXml;

response = SendRequest(url, request);

System.Diagnostics.Debug.WriteLine(response);
 

// retrieve the response message's status code and text value

doc = null;

doc = new XmlDocument();

doc.LoadXml(response);

XmlNode node = doc.DocumentElement.SelectSingleNode("/cXML/Response/Status");

if(node != null)

{

	result.AddMessage(string.Format("The Order Request was posted to <Vendor Name> and returned: {0}/{1}", node.Attributes.Item(1).Value, node.Attributes.Item(0).Value));
 

	// POImporter is a class that I built to import the PO (similar to a cXML Order Request) into our ERP system; not needed by you obviously

	POImporter poImporter = new POImporter(fsimp, dsOrderDetails);

	poImporter.PONumber = poNumber;

	poImporter.POShipToName = shipToName;
 

	poImporter.Import(ref result);
 

	if(result.IsValid)

	{

		// archive pending order records

		((frmMain)fMain).Order.PendingOrderArchive(poNumber);
 

		result.AddMessage("The purchase order information was archived successfully.");

		result.AddMessage("You can review previous order history by opening the Order History screen.");

	}

	else

	{

		result.AddInvalidatingMessage("The order process did NOT complete successfully.  Please contact the IT department (Josh, Jill, or Larry)");

		result.AddInvalidatingMessage("NOTE: the supplier got the purchase order but the po was not imported into our ERP system.");

	}

Open in new window

0
 

Author Comment

by:apheggie
Comment Utility
Is there a way I can test to see if it is posting to the defined page? I have added the code but I am getting nothing back.
0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
Notice the line below:

response = SendRequest(url, request);

The response should contain the stream that Amazon returns (which should be a cXML response).  Are you able to set a breakpoint in your IDE and step through the lines of code in question?
0
 

Author Comment

by:apheggie
Comment Utility
No I can not. It is on a hosted server.

I have attached my code (be it as quick & dirty as possible)

Do you see anything obviously wrong?

CXMLString = "<?xml version='1.0' encoding='UTF-8'?>"

CXMLString = CXMLString & "<!DOCTYPE cXML SYSTEM 'http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd'>"

CXMLString = CXMLString & "<cXML xml:lang='en-US' version='1.2.014' timestamp='2008-10-09T18:25:49-07:00' payloadID='99926478586398498529@bizrewards.biz'>"

CXMLString = CXMLString & "<Header>"

CXMLString = CXMLString & "<From>"

CXMLString = CXMLString & "<Credential domain='AmazonCustomerID'>"

CXMLString = CXMLString & "<Identity>xxxxx</Identity>"

CXMLString = CXMLString & "</Credential>"

CXMLString = CXMLString & "</From>"

CXMLString = CXMLString & "<To>"

CXMLString = CXMLString & "<Credential domain='CompanyName'>"

CXMLString = CXMLString & "<Identity>Amazon.com</Identity>"

CXMLString = CXMLString & "</Credential>"

CXMLString = CXMLString & "</To>"

CXMLString = CXMLString & "<Sender>"

CXMLString = CXMLString & "<Credential domain='AmazonCustomerId'>"

CXMLString = CXMLString & "<Identity>xxxxx</Identity>"

CXMLString = CXMLString & "<SharedSecret>xxxxx</SharedSecret>"

CXMLString = CXMLString & "</Credential> "

CXMLString = CXMLString & "<UserAgent>Buyer 8.2</UserAgent>"

CXMLString = CXMLString & "</Sender>"

CXMLString = CXMLString & "</Header> <Request> <OrderRequest>  <OrderRequestHeader orderID='DO102880' orderDate='2008-10-09' type='new' shipComplete='yes'> <Total> <Money currency='USD'>242.04</Money> </Total> <ShipTo> <Address> <Name xml:lang='en'> John Q. Smith</Name> <PostalAddress name='default'> <DeliverTo>John Q. Smith</DeliverTo> <Street>123 Fourth Ave</Street> <City>Seattle</City> <State>WA</State> <PostalCode>94089</PostalCode> <Country isoCountryCode='US'>United States</Country> </PostalAddress> <Email name='default'>john_smith@acme.com</Email> <Phone name='work'> <TelephoneNumber> <CountryCode isoCountryCode='United States'>1</CountryCode> <AreaOrCityCode>800</AreaOrCityCode> <Number>5555555</Number> </TelephoneNumber> </Phone> </Address> </ShipTo> <BillTo> <Address> <Name xml:lang='en'>Acme Accounts Payable</Name> <PostalAddress name='default'> <Street>124 Union Street</Street> <City>San Francisco</City> <State>CA</State> <PostalCode>94128</PostalCode>  <Country isoCountryCode='US'>United States</Country> </PostalAddress> <Phone name='work'> <TelephoneNumber> <CountryCode isoCountryCode='US'>1</CountryCode> <AreaOrCityCode>415</AreaOrCityCode> <Number>6666666</Number> </TelephoneNumber> </Phone> </Address> </BillTo> <Shipping> <Money currency='USD'>12.34</Money> <Description xml:lang='en-US'>SecondDay</Description> </Shipping> <Tax> <Money currency='USD'>10.74</Money> <Description xml:lang='en'>WA State Tax</Description> </Tax> <Payment> <PCard name='Acme Accounts Payable' number='1234567890123456' expiration='2006-05-04'/> </Payment>  <Extrinsic name='AssociateId'>1232t6</Extrinsic> </OrderRequestHeader> <ItemOut quantity='2' lineNumber='1'> <ItemID>  <SupplierPartID>B00004RALR</SupplierPartID>  <SupplierPartAuxiliaryID>2Fa4NZyod</SupplierPartAuxiliaryID> </ItemID><ItemDetail> <UnitPrice> <Money currency='USD'>109.48</Money> </UnitPrice> 	<Description xml:lang='en-US'>Webber Grill</Description> <UnitOfMeasure>EA</UnitOfMeasure> <Classification domain='ISBN'>12345678</Classification> <Extrinsic name='GiftMessage'>Your gift message here</Extrinsic> <Extrinsic name='MerchantID'>ATVPDKIKX0DER</Extrinsic> </ItemDetail> </ItemOut> </OrderRequest> </Request> </cXML>"

SendRequest("https://punchoutgateway-integration.amazon.com/cxml/OrderRequest", CXMLString)
 
 

    Sub SendRequest(ByVal url As String, ByVal request As String)

        Dim req As HttpWebRequest

        Dim resp As HttpWebResponse
 

        Try
 

            Dim data As Byte() = New UTF8Encoding().GetBytes(request)
 

            req = WebRequest.Create(url)

            req.Method = "POST"

            req.ContentLength = data.Length

            req.ContentType = "text/xml"

            req.AllowAutoRedirect = True

            req.KeepAlive = False

            req.AllowWriteStreamBuffering = True
 

            req.ReadWriteTimeout = 60000

            req.ServicePoint.MaxIdleTime = 100000
 

            Dim myStream As Stream

            myStream = req.GetRequestStream()

            myStream.Write(data, 0, data.Length)
 
 

            resp = req.GetResponse()

            If req.HaveResponse Then

                If (resp.StatusCode = HttpStatusCode.OK Or resp.StatusCode = HttpStatusCode.Accepted) Then

                    Dim sr = New StreamReader(resp.GetResponseStream)

                    Dim strHTML As String = sr.ReadToEnd

                    Label3.Text = "Returned " & strHTML

                Else

                    Label1.Text = Label1.Text & "Request failed: " + resp.StatusDescription

                End If

            End If

        Catch ex As Exception

            Label1.Text = Label1.Text & ex.Message
 

        End Try
 

End Sub

Open in new window

0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
apheggie,

I created a test ASP.NET project that uses your code and had it post to my http://localhost/ReceiveXML/cXML/default.aspx URL that I gave you originally.  Your POST code works but the results aren't rendered in the Label3.Text properly.  Try running your code again against Amazon.  Then when your code finishes executing, view the HTML source of your test page (with the blank labels).  You should see Amazon's cXML XML response.  Let me know how you get on.

You could also add logic to parse the cXML response and determine if it is valid/success.

Cheers,
Josh
0
 
LVL 1

Accepted Solution

by:
JoshBlair earned 500 total points
Comment Utility
Here is that the source looks like when I view source after using your POST code to post to my test URL:

Actually, try replacing Label3 with a Liter and setting the Literal1.Text control using encoding like this and the XML response will show the XML...

 Literal1.Text = "<pre>" & Server.HtmlEncode(strHTML) & "</pre>"

Note: The top XML Response listed below is from a Response.Write line but it doesn't show up on the rendered HTML output either.

Good Luck,
Josh
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.1.006/cXML.dtd">

<cXML version="1.0" payloadID="123" timestamp="2008-10-10T17:44:53-06:00">

  <Response>

    <Status code="200" text="success" />

  </Response>

</cXML>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head><title>

	Untitled Page

</title></head>

<body>
 

    <form name="form1" method="post" action="Post.aspx" id="form1">

<div>

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMjc5NDgwOTA0D2QWAgIDD2QWAgIHDxYCHgRUZXh0BZMDPHByZT4mbHQ7P3htbCB2ZXJzaW9uPSZxdW90OzEuMCZxdW90OyBlbmNvZGluZz0mcXVvdDt1dGYtOCZxdW90Oz8mZ3Q7DQombHQ7IURPQ1RZUEUgY1hNTCBTWVNURU0gJnF1b3Q7aHR0cDovL3htbC5jeG1sLm9yZy9zY2hlbWFzL2NYTUwvMS4xLjAwNi9jWE1MLmR0ZCZxdW90OyZndDsNCiZsdDtjWE1MIHZlcnNpb249JnF1b3Q7MS4wJnF1b3Q7IHBheWxvYWRJRD0mcXVvdDsxMjMmcXVvdDsgdGltZXN0YW1wPSZxdW90OzIwMDgtMTAtMTBUMTc6NDQ6NTMtMDY6MDAmcXVvdDsmZ3Q7DQogICZsdDtSZXNwb25zZSZndDsNCiAgICAmbHQ7U3RhdHVzIGNvZGU9JnF1b3Q7MjAwJnF1b3Q7IHRleHQ9JnF1b3Q7c3VjY2VzcyZxdW90OyAvJmd0Ow0KICAmbHQ7L1Jlc3BvbnNlJmd0Ow0KJmx0Oy9jWE1MJmd0OzwvcHJlPmRkmE1prWgBROg+DQAFFXvwcPu1k0k=" />

</div>
 

    <div>

    

    </div>

    <span id="Label1">Label</span>

    <p>

        <span id="Label2">Label</span>
 

    </p>

    <p>

        <span id="Label3">Label</span>

    </p>

    <p>

        <pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
 

&lt;!DOCTYPE cXML SYSTEM &quot;http://xml.cxml.org/schemas/cXML/1.1.006/cXML.dtd&quot;&gt;

&lt;cXML version=&quot;1.0&quot; payloadID=&quot;123&quot; timestamp=&quot;2008-10-10T17:44:53-06:00&quot;&gt;

  &lt;Response&gt;

    &lt;Status code=&quot;200&quot; text=&quot;success&quot; /&gt;
 

  &lt;/Response&gt;

&lt;/cXML&gt;</pre>

    </p>

    </form>

</body>

</html>

Open in new window

0
 

Author Comment

by:apheggie
Comment Utility
Sorry for delay in responding back. I had mutiple emergency week.

Anyway - I wanted to thank you for your help! You saved me!

I have attached the Amazon documentation for you.



[Attachment deleted per request of Amazon.com]

Vee_Mod

Open in new window

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Closing Comment

by:apheggie
Comment Utility
Thank you sooooo much for your help. You saved me. I have attached the Amazon info to the question.
0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
Great, glad to help.  Cheers,
0
 

Expert Comment

by:skimox
Comment Utility
I am new to cXML request/response. The following code is what I am using based on what I've learned from the previous post 'Amazon CXML post and retrival in ASP'.

Can anyone provide assistance?

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="ISO-8859-1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<% Public Sub SendRequest(ByVal url As String, ByVal request As String)

        Dim req As HttpWebRequest

        Dim resp As HttpWebResponse

 

        Try

 

            Dim data As Byte() = New UTF8Encoding().GetBytes(request)

 

            req = WebRequest.Create(url)

            req.Method = "POST"

            req.ContentLength = data.Length

            req.ContentType = "text/xml"

            req.AllowAutoRedirect = True

            req.KeepAlive = False

            req.AllowWriteStreamBuffering = True

 

            req.ReadWriteTimeout = 60000

            req.ServicePoint.MaxIdleTime = 100000

 

            Dim myStream As Stream

            myStream = req.GetRequestStream()

            myStream.Write(data, 0, data.Length)

 

 

            resp = req.GetResponse()

            If req.HaveResponse Then

                If (resp.StatusCode = HttpStatusCode.OK Or resp.StatusCode = HttpStatusCode.Accepted) Then

                    Dim sr = New StreamReader(resp.GetResponseStream)

                    Dim strHTML As String = sr.ReadToEnd

                    Label3.Text = "Returned " & strHTML

                Else

                    Label1.Text = Label1.Text & "Request failed: " + resp.StatusDescription

                End If

            End If

        Catch ex As Exception

            Label1.Text = Label1.Text & ex.Message

 

        End Try

 

End Sub
 

%>
 

<%

Dim CXMLString = ""
 

CXMLString = "<?xml version='1.0' encoding='UTF-8'?>"

CXMLString = CXMLString & "<!DOCTYPE cXML SYSTEM 'http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd'>"

CXMLString = CXMLString & "<cXML xml:lang='en-US' version='1.2.014' timestamp='2008-12-23T18:25:49-07:00' payloadID='test@specialtyprintcomm.com'>"

CXMLString = CXMLString & "<Response>"

CXMLString = CXMLString & "<Status code=" & chr(34) & "200" & chr(34) & "text=" & chr(34) & "success" & chr(34) & "></Status>"

CXMLString = CXMLString & "<PunchOutSetupResponse>"

CXMLString = CXMLString & "<StartPage>"

CXMLString = CXMLString & "<URL>http://www.hotleadsmanager.com"

CXMLString = CXMLString & "</URL>"

CXMLString = CXMLString & "</StartPage>"

CXMLString = CXMLString & "</PunchOutSetupResponse>"

CXMLString = CXMLString & "</Response>"

CXMLString = CXMLString & "</cXML>"
 
 
 
 

SubSendRequest("https://stagingportal.ketera.com/procurement/uReceiveOrder705309Message.do", CXMLString)
 

%>

Open in new window

0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
What is your problem?  Are you getting errors?
0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
What is your problem?  Are you getting errors?
0
 

Expert Comment

by:skimox
Comment Utility
I am getting an error: 'Statement cannot appear within a method body.'

Its referring to the sub routine: 'SendRequest'.
0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
skimox,

I put together a sample for you in ASP.NET 1.1 using VB.NET with a code behind model.

I have attached it for your review.  You will need to change the URL that is being posted to to your own post url to test (https://stagingportal.ketera.com/procurement/uReceiveOrder705309Message.do).  I test my code against a local ASP.NET app that I built for the purpose of testing my cXML applications.

You will want to look at post2.aspx & post2.aspx.vb

Hope this helps,

Josh Blair
Golden, CO
0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
The attachment doesn't appear to have taken.  Second try...
0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
The attachments aren't working...maybe because I am not a paying member???

See below for the contents of the webform code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Post2.aspx.vb" Inherits="cXMLPost.Post2" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>cXML Post Test</title>

</head>

<body>

    <form id="form1" runat="server">

    <p>

        <asp:Label ID="Label1" runat="server" Text=""></asp:Label></p>

    <p>

        <asp:Literal ID="Literal1" runat="server"></asp:Literal></p>

    </form>

</body>

</html>

Open in new window

0
 
LVL 1

Expert Comment

by:JoshBlair
Comment Utility
See below for the code in the page behind:
Imports System.Net

Imports System.IO
 

Partial Public Class Post2

    Inherits System.Web.UI.Page
 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        PostTest()

    End Sub
 

    Sub PostTest()

        Dim CXMLString = ""
 

        CXMLString = "<?xml version='1.0' encoding='UTF-8'?>"

        CXMLString = CXMLString & "<!DOCTYPE cXML SYSTEM 'http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd'>"

        CXMLString = CXMLString & "<cXML xml:lang='en-US' version='1.2.014' timestamp='2008-12-23T18:25:49-07:00' payloadID='test@specialtyprintcomm.com'>"

        CXMLString = CXMLString & "<Response>"

        CXMLString = CXMLString & "<Status code=" & Chr(34) & "200" & Chr(34) & "text=" & Chr(34) & "success" & Chr(34) & "></Status>"

        CXMLString = CXMLString & "<PunchOutSetupResponse>"

        CXMLString = CXMLString & "<StartPage>"

        CXMLString = CXMLString & "<URL>http://www.hotleadsmanager.com"

        CXMLString = CXMLString & "</URL>"

        CXMLString = CXMLString & "</StartPage>"

        CXMLString = CXMLString & "</PunchOutSetupResponse>"

        CXMLString = CXMLString & "</Response>"

        CXMLString = CXMLString & "</cXML>"
 

        SendRequest("http://localhost/ReceiveXML/cxml/default.aspx", CXMLString)

    End Sub
 

    Sub SendRequest(ByVal url As String, ByVal request As String)

        Dim req As HttpWebRequest

        Dim resp As HttpWebResponse
 

        Try
 

            Dim data As Byte() = New UTF8Encoding().GetBytes(request)
 

            req = WebRequest.Create(url)

            req.Method = "POST"

            req.ContentLength = data.Length

            req.ContentType = "text/xml"

            req.AllowAutoRedirect = True

            req.KeepAlive = False

            req.AllowWriteStreamBuffering = True
 

            req.ReadWriteTimeout = 60000

            req.ServicePoint.MaxIdleTime = 100000
 

            Dim myStream As Stream

            myStream = req.GetRequestStream()

            myStream.Write(data, 0, data.Length)
 
 

            resp = req.GetResponse()

            If req.HaveResponse Then

                If (resp.StatusCode = HttpStatusCode.OK Or resp.StatusCode = HttpStatusCode.Accepted) Then

                    Dim sr = New StreamReader(resp.GetResponseStream)

                    Dim strHTML As String = sr.ReadToEnd

                    Response.Write(strHTML)

                    Literal1.Text = "<pre>" & Server.HtmlEncode(strHTML) & "</pre>"

                Else

                    Label1.Text = Label1.Text & "Request failed: " + resp.StatusDescription

                End If

            End If

        Catch ex As Exception

            Label1.Text = Label1.Text & ex.Message
 

        End Try
 

    End Sub
 

End Class

Open in new window

0
 

Expert Comment

by:skimox
Comment Utility
I will admit that I am a newbie at both .net and cXML. So I apologize if I'm missing the obvious. I really appreciate your help.

I have posted the two pages: post2.aspx and post2.aspx.vb with the code as you tested. I also replace the local test server with my ecommerce webhost.

I am getting this error when loading post2.aspx: 'Could not load type 'cXMLPost.Post2'.

Todd
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now