I did some searching on the help forms and found alot out about the Handler and started playing with a test file. It took me a couple of hours, but I managed to get one of my test forms to post an XML file to the handler.
It got me pumped when I got that to happen, I got me alot closer to having a solution. I will be testing my test handler online from the live site tomorrow. If all gose well then I have managed to get the solution, I will let you know latter how it is going.
OK now this is getting me really upset. The following is a sample of the Handler I have created, slitely modifyed.
public class hndTest1 : IHttpHandler {
private Boolean m_success = true;
public void ProcessRequest(HttpContext xmlText)
{
XmlTextReader tstReader = new XmlTextReader(xmlText.Request.InputStream0;
XmlValidatingReader reader = new XmlValidatingReader(tstReader);
reader.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
reader.Read();
while (reader.Read())
{
//Extra code to parse the elements and check for trigers
}
XmlDocument tstXmlDoc = new XmlDocument();
XmlDeclaration tstDeclaration = tstXmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
XmlElement rootNode = tstXmlDoc.CreateElement("xiamSMS");
tstXmlDoc.InsertBefore(xmlDeclaration, tstXmlDoc.DocumentElement);
tstXmlDoc.AppendChild(rootNode);
The problem is that the validation file xiamSMSMessage.dtd creates a couple of issues. I had the third party company send me a copy of this file, since I did not have it. Now how do I handle the validation for this file in my code so that it will not generate
any errors from the PHP posting form all the while allowing me to parse the XML data passed and return back an XML document confirming the recieving of the data?
Any thoughts on how to accomplish this would be greatly accepted, I am under a time constraint.
I have made some progress in a test file. I have confirmed that I can receive an XML file and as long as I send back a string version of my responce XML I am find. The new test file works and works with no errors.
Now my issue is opening up the XML file I am sent and getting around the validation file line, (<!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd">).
I am opening the file with an XmlTextReader object, the advantage is that it allows me to read down the XML file and take out the different parts. Based on these parts I can build a responce XML and insert parts of the reading filoe into the responce. But
I get tripped up on the DOCTYPE line, the minute my file reads that it has issues.
Is there a way to step past that line and not even load it into memory, so as to bypass it?
Or what code do I need to add that will allow my system to work with the Doctype and this DTD file?
Help please, if I can solve this I can get the site up and running.
Sorry, I'll take a look at your stuff in detail tommorrow...being turkey day and all I'm a bit distracted. Also I have to go back in time to use the old XMlDocument stuff.... I'm an xml to linq guy these days and dont' use the old namespaces your dealing
with. I'll take some time to look at it. Out the gate I think your probably required to use proper DTD when using the xmlvalidating stuff....but I could be wrong, like I said I need to research. I should have some time tommorrow to try to help ya figure
it out though.
Brian
Developer
Marked as answer by JRatcliff on Nov 28, 2010 05:34 PM
Thanks Brian you helped to solve my first problem so I am marking this one solved. I am creating another for the XML reading issue I am encountering. I will use the title "Problem reading an XML file with a DTD attached" if you are interested in helping
out.
For those looking for the answer to my first problem. When designing a web service to recieve a HTTP Post of an XML from a PHP page, use a Generic Handler file to accept the HTTP Post and open the HttpContext variable and access the XML information by opening
up the var.Request.InputStream. I found this solution to work better than using a Web Service and allowed me to accept the post.
Ultimately the use of SOAP is better for passing XML but when you have very little choice this could work.
JRatcliff
Member
47 Points
34 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 23, 2010 02:36 AM|LINK
Thanks Brian.
I did some searching on the help forms and found alot out about the Handler and started playing with a test file. It took me a couple of hours, but I managed to get one of my test forms to post an XML file to the handler.
It got me pumped when I got that to happen, I got me alot closer to having a solution. I will be testing my test handler online from the live site tomorrow. If all gose well then I have managed to get the solution, I will let you know latter how it is going.
Thanks
JRatcliff
Blast2hell
Member
428 Points
86 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 23, 2010 02:42 AM|LINK
cool, let me know if you hit any snags
Developer
JRatcliff
Member
47 Points
34 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 24, 2010 07:47 PM|LINK
OK now this is getting me really upset. The following is a sample of the Handler I have created, slitely modifyed.
public class hndTest1 : IHttpHandler {
private Boolean m_success = true;
public void ProcessRequest(HttpContext xmlText)
{
XmlTextReader tstReader = new XmlTextReader(xmlText.Request.InputStream0;
XmlValidatingReader reader = new XmlValidatingReader(tstReader);
reader.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
reader.Read();
while (reader.Read())
{
//Extra code to parse the elements and check for trigers
}
XmlDocument tstXmlDoc = new XmlDocument();
XmlDeclaration tstDeclaration = tstXmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
XmlElement rootNode = tstXmlDoc.CreateElement("xiamSMS");
tstXmlDoc.InsertBefore(xmlDeclaration, tstXmlDoc.DocumentElement);
tstXmlDoc.AppendChild(rootNode);
XmlElement parentNode = tstXmlDoc.CreateElement("deliverResponse");
parentNode.SetAttribute("id", "123456");
tstXmlDoc.DocumentElement.PrependChild(parentNode);
XmlElement resultNode = tstXmlDoc.CreateElement("result");
resultNode.SetAttribute("status", "OK");
XmlText resultText = tstXmlDoc.CreateTextNode("+1234567890");
parentNode.AppendChild(resultNode);
resultNode.AppendChild(resultText);
xmlText.Response.ContentType = "text/xml";
xmlText.Response.Write(tstXmlDoc);
}
public bool IsReusable {
get {
return false;
}
}
private void ValidationCallBack(object sender, ValidationEventArgs args)
{
m_success = false;
}
}
Now what I have to recieve is the following XML or something similare.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd">
<xiamSMS>
<deliverRequest id="1">
<from>+14165551234</from>
<to>+467228</to>
<content type="text">HELP</content>
<receivedOnGroup value="NONE" />
<xirMessageID value="1" />
</deliverRequest>
</xiamSMS>
The problem is that the validation file xiamSMSMessage.dtd creates a couple of issues. I had the third party company send me a copy of this file, since I did not have it. Now how do I handle the validation for this file in my code so that it will not generate any errors from the PHP posting form all the while allowing me to parse the XML data passed and return back an XML document confirming the recieving of the data?
Any thoughts on how to accomplish this would be greatly accepted, I am under a time constraint.
Thanks
JRatcliff
JRatcliff
Member
47 Points
34 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 25, 2010 10:09 PM|LINK
I have made some progress in a test file. I have confirmed that I can receive an XML file and as long as I send back a string version of my responce XML I am find. The new test file works and works with no errors.
Now my issue is opening up the XML file I am sent and getting around the validation file line, (<!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd">).
I am opening the file with an XmlTextReader object, the advantage is that it allows me to read down the XML file and take out the different parts. Based on these parts I can build a responce XML and insert parts of the reading filoe into the responce. But I get tripped up on the DOCTYPE line, the minute my file reads that it has issues.
Is there a way to step past that line and not even load it into memory, so as to bypass it?
Or what code do I need to add that will allow my system to work with the Doctype and this DTD file?
Help please, if I can solve this I can get the site up and running.
Thanks
JRatcliff
Blast2hell
Member
428 Points
86 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 25, 2010 11:29 PM|LINK
Sorry, I'll take a look at your stuff in detail tommorrow...being turkey day and all I'm a bit distracted. Also I have to go back in time to use the old XMlDocument stuff.... I'm an xml to linq guy these days and dont' use the old namespaces your dealing with. I'll take some time to look at it. Out the gate I think your probably required to use proper DTD when using the xmlvalidating stuff....but I could be wrong, like I said I need to research. I should have some time tommorrow to try to help ya figure it out though.
Developer
JRatcliff
Member
47 Points
34 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 26, 2010 04:07 AM|LINK
Thanks Brian I will wait and see what you can come up with, so far you have been a great help with your suggestion to use a Handler file.
Thanks
JRatcliff
JRatcliff
Member
47 Points
34 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 28, 2010 05:48 PM|LINK
Thanks Brian you helped to solve my first problem so I am marking this one solved. I am creating another for the XML reading issue I am encountering. I will use the title "Problem reading an XML file with a DTD attached" if you are interested in helping out.
For those looking for the answer to my first problem. When designing a web service to recieve a HTTP Post of an XML from a PHP page, use a Generic Handler file to accept the HTTP Post and open the HttpContext variable and access the XML information by opening up the var.Request.InputStream. I found this solution to work better than using a Web Service and allowed me to accept the post.
Ultimately the use of SOAP is better for passing XML but when you have very little choice this could work.