Solved

Amazon CXML post and retrival in ASP

Posted on 2008-10-09
23
2,514 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 6
  • 3
23 Comments
 
LVL 1

Expert Comment

by:JoshBlair
ID: 22687475
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
ID: 22687634
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
ID: 22687863
Sorry for odd  first response. I was up to 3:00AM fighting this code. I would LOVE to have your help!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:JoshBlair
ID: 22688273
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
ID: 22688451
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
ID: 22690138
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
ID: 22690244
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
ID: 22690405
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
ID: 22691619
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
ID: 22691684
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
ID: 22728307
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
 

Author Closing Comment

by:apheggie
ID: 31504922
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
ID: 22731170
Great, glad to help.  Cheers,
0
 

Expert Comment

by:skimox
ID: 23236844
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
ID: 23236901
What is your problem?  Are you getting errors?
0
 
LVL 1

Expert Comment

by:JoshBlair
ID: 23236903
What is your problem?  Are you getting errors?
0
 

Expert Comment

by:skimox
ID: 23236955
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
ID: 23237312
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
ID: 23237322
The attachment doesn't appear to have taken.  Second try...
0
 
LVL 1

Expert Comment

by:JoshBlair
ID: 23237334
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
ID: 23237339
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
ID: 23237862
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

615 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