I have been strugleing with this for more than a week, and have not been able to get any further ahead. I need to create a Webservice that can recive an HTTP Post with an XML document as the body or payload. It will be comeing from a PHP site, and I need
to access it in ASP.Net.
I can create a webservice and test it out correctly with no real hitch, but when testing with my third partys test page I am not getting the proper responce. The third party company can not provide me with much help since they do not know ASP.
The following is a sample code peice that can open a string of XML passed, and I have a form that can post to this test page.
public XmlDocument ProcessXML(String SourceXML)
{
XmlDocument NewSourceXML = new XmlDocument();
NewSourceXML.LoadXml(SourceXML);
.....
}
I knoiw that once I can read the posted XML I can break it down and do what I need to do with it, but I am having issues reciving the XML at this point.
My third party provided me with a basic excert from a PHP file.
/*
* Get the HTTP request (body) and parse into an XML document
*/
$data = file_get_contents("php://input");
$xmlstr = trim( stripslashes( $data ) );
$xml = new SimpleXMLElement($xmlstr);
But this is of no help to me. I need to solve this so I can start reciving XML transmissions from this company.
The XML data is being posted to the WebService I can only think it is being passed as an XML file structure. I have for the time being setup my procedure to receive a String, and have not had any luck setting it up to recieve a XML data transmission. The
excert of the PHP code is what they use to recieve the XML, I have not found anything that is simular in ASP with C# Script.
The Third party is performing a HTTP Post, the test page is doing it from a form with a couple of jscripts. If you would like to see the test page you can see it at the following URL.
I have had to use FireFox to use the page, IE presents the ability to save a file so I have not been able to use IE on this test site. My WebService is located at the following URL.
Hi, well first, to solve this problem you need to take a more stepped approach.
First, make sure you can get the webservice to work for you, completely, and then worry about the third party with the PHP page. You'd be surprised how many PHP have no idea how to interact with webservices, so you may be against a technical challenge there
even if your webservice was the best thing since sliced bread.
Due to technical limitations of your client, you may want to consider possibly building an httphandler instead, and then having them hit that instead passing request parameters as appropriate....lots of time PHP people are a bit better with that sort of
basic tech.
None the less you need to make sure your enviroment works perfectly fine before you involve your client. In this case you should build a seperate website perhaps that consumes the service you built, and pass your own tests to it. If you do this all in one
solution you should be able to easily step through the code to see how things are going.
Also, if you expect XML from someone else, you may want to learn how to build an xml validator that way you can validate the xml your receiving. You can never assume the client is going to pass you something appropriate...users always do what you don't
expect.
public XmlDocument ProcessXML(String SourceXML)
{
XmlDocument NewSourceXML = new XmlDocument();
NewSourceXML.LoadXml(SourceXML);
.....
}
Additionally, what version of .Net are you using? if your using 3.5 or higher, you may want to move the the Linq to XML structure, personally I find it a lot easier to work with.
In this case your code would be
XDocument sourceXml = XDocument.Parse(SourceXML);
Then you can query against, it, but definately need to validate the xml...who knows what kinda garbly goop they could send you.
Thanks for your ideas Blast2hell, I have already got a WebService that validates the XML based on the type of transmission my third party is to send. It even sends an XML transmission back confirming and replying to the transwmission.
The problem seams to be with the variable that is meant to recieve the XML transmission from the PHP form. When I use a String variable, the testing service works fine when I hit the page directly with IE and invoke the rotine, but from the PHP test page
using the HTTP Post I get an error reported of "Server returned status 500: Internal Server Error". I am guessing that the post is not passing a string through the post.
A sample of the test XML is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xiamSMS SYSTEM "xiamSMSMessage.dtd">
I just have to be able to recive this XML through a post once I have it I know I can break it down, store it, and return a validation in XML. There of course are a lot of other alterations to this XML and it will be posible for this to have multiple deliverRequest
cells in the live one. This is just a test XML to be used to confirm the ability to recive from my third party.
Also, I have tried using an XmlDocument variable, but the service responds with "The test form is only available for requests from the local machine." and can not be invoked through IE, and of course the test form responds with "Server returned status 500:
Internal Server Error."
So the question still stands, How do I setup a WebService to accept a XML data transmission from a PHP form using an HTTP Post with the XML as the body of the post? This third party is not willing to use SOAP to transmitte the XML whitch would be the proper
way for ASP.
Any help that you can provide would be greatly accepted.
Right now it looks like your ProcessXML method is looking for a parameter to be passed to it of the type System.Xml.XmlNode. I think the php people may have trouble making the xmlnode type.
Also the php people will most likely need to download a tool or something to assist them with connection to a webservice. Like wsdl2php or NuSoap.
Did I understand you correctly that you've created your own test application, and invoked your webservice and everything worked?
I'm still of the mind that you probably need to do a webhandler instead.
An interesting idea, but I have never created a webhandler before. I need to have something that can accept an XML file through a post and after parsing the XML I will need to return back an XML responce confirming the transmission. I have no problem parsing
the XML, and I have no issues returning an XML responce. I felt the WebService process was the best way to approach it.
This WebHandler you have mentioned, how would I go about setting up this to recive the HTTP Post from PHP with an XML in the body of the post?
well keep in mind I'm not saying your webservice won't work, I'm just saying it may be technically to much for your php people. I could also be a bit bias against PHP people hehe.
Anyways. to answer your question. You would open an existing web application, or create a new one, based on your scenaior. And right click the project and choose "Add new item". And then Choose Generic Handler. The file type for these is .ashx. Rename
it to something appopriate...like XmlReciver.ashx.
Handlers can be used to input and output all sorts of things....you can treat it like a normal web page, and access Request parameters...the site can then post the xml string as a url parameter...for instance
And then you can output the response appropriately. You'd most likely be able to take whatever code you had for your webservice already and put it in the handler, or even just have your handler call your webservice.
Brian
Brian
Developer
Marked as answer by JRatcliff on Nov 28, 2010 05:49 PM
JRatcliff
Member
47 Points
34 Posts
Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from a P...
Nov 18, 2010 10:53 PM|LINK
Helllo;
I have been strugleing with this for more than a week, and have not been able to get any further ahead. I need to create a Webservice that can recive an HTTP Post with an XML document as the body or payload. It will be comeing from a PHP site, and I need to access it in ASP.Net.
I can create a webservice and test it out correctly with no real hitch, but when testing with my third partys test page I am not getting the proper responce. The third party company can not provide me with much help since they do not know ASP.
The following is a sample code peice that can open a string of XML passed, and I have a form that can post to this test page.
public XmlDocument ProcessXML(String SourceXML)
{
XmlDocument NewSourceXML = new XmlDocument();
NewSourceXML.LoadXml(SourceXML);
.....
}
I knoiw that once I can read the posted XML I can break it down and do what I need to do with it, but I am having issues reciving the XML at this point.
My third party provided me with a basic excert from a PHP file.
/*
* Get the HTTP request (body) and parse into an XML document
*/
$data = file_get_contents("php://input");
$xmlstr = trim( stripslashes( $data ) );
$xml = new SimpleXMLElement($xmlstr);
But this is of no help to me. I need to solve this so I can start reciving XML transmissions from this company.
Thanks for any help you can give.
sachingusain
Star
8786 Points
1702 Posts
Re: Creating a Web Service to Recive a HTTP POST with an XML document as the body or payload from...
Nov 19, 2010 01:32 PM|LINK
so the XML document is being passed as a string parameter. Correct?
Are they able to hit the URL for web service from their box? If yes, then ask them to provide details of errors they are getting.
Thanks.
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 19, 2010 04:37 PM|LINK
The XML data is being posted to the WebService I can only think it is being passed as an XML file structure. I have for the time being setup my procedure to receive a String, and have not had any luck setting it up to recieve a XML data transmission. The excert of the PHP code is what they use to recieve the XML, I have not found anything that is simular in ASP with C# Script.
The Third party is performing a HTTP Post, the test page is doing it from a form with a couple of jscripts. If you would like to see the test page you can see it at the following URL.
https://lab.jumptxt.com/smsxml-test-suite/DeliverRequest.action
I have had to use FireFox to use the page, IE presents the ability to save a file so I have not been able to use IE on this test site. My WebService is located at the following URL.
http://smsnetca.w03.winhost.com/Service/wsTest1.asmx/ProcessXML
The error I am getting is the following.
com.impact.exception.FatalException: Server returned status 500: Internal Server Error
Any help you can provide would be helpfull.
Thanks
.net web service "ASP.NET" .ascx .aspx C# .ASPX .net 3.5 "web service"
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 19, 2010 08:42 PM|LINK
Hi, well first, to solve this problem you need to take a more stepped approach.
First, make sure you can get the webservice to work for you, completely, and then worry about the third party with the PHP page. You'd be surprised how many PHP have no idea how to interact with webservices, so you may be against a technical challenge there even if your webservice was the best thing since sliced bread.
Due to technical limitations of your client, you may want to consider possibly building an httphandler instead, and then having them hit that instead passing request parameters as appropriate....lots of time PHP people are a bit better with that sort of basic tech.
None the less you need to make sure your enviroment works perfectly fine before you involve your client. In this case you should build a seperate website perhaps that consumes the service you built, and pass your own tests to it. If you do this all in one solution you should be able to easily step through the code to see how things are going.
Also, if you expect XML from someone else, you may want to learn how to build an xml validator that way you can validate the xml your receiving. You can never assume the client is going to pass you something appropriate...users always do what you don't expect.
Developer
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 19, 2010 08:45 PM|LINK
Additionally, what version of .Net are you using? if your using 3.5 or higher, you may want to move the the Linq to XML structure, personally I find it a lot easier to work with.
In this case your code would be
XDocument sourceXml = XDocument.Parse(SourceXML);
Then you can query against, it, but definately need to validate the xml...who knows what kinda garbly goop they could send you.
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 20, 2010 04:11 PM|LINK
Thanks for your ideas Blast2hell, I have already got a WebService that validates the XML based on the type of transmission my third party is to send. It even sends an XML transmission back confirming and replying to the transwmission.
The problem seams to be with the variable that is meant to recieve the XML transmission from the PHP form. When I use a String variable, the testing service works fine when I hit the page directly with IE and invoke the rotine, but from the PHP test page using the HTTP Post I get an error reported of "Server returned status 500: Internal Server Error". I am guessing that the post is not passing a string through the post.
A sample of the test XML is as follows:
<?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>
I just have to be able to recive this XML through a post once I have it I know I can break it down, store it, and return a validation in XML. There of course are a lot of other alterations to this XML and it will be posible for this to have multiple deliverRequest cells in the live one. This is just a test XML to be used to confirm the ability to recive from my third party.
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 20, 2010 04:19 PM|LINK
Also, I have tried using an XmlDocument variable, but the service responds with "The test form is only available for requests from the local machine." and can not be invoked through IE, and of course the test form responds with "Server returned status 500: Internal Server Error."
So the question still stands, How do I setup a WebService to accept a XML data transmission from a PHP form using an HTTP Post with the XML as the body of the post? This third party is not willing to use SOAP to transmitte the XML whitch would be the proper way for ASP.
Any help that you can provide would be greatly accepted.
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 21, 2010 03:59 AM|LINK
Right now it looks like your ProcessXML method is looking for a parameter to be passed to it of the type System.Xml.XmlNode. I think the php people may have trouble making the xmlnode type.
Also the php people will most likely need to download a tool or something to assist them with connection to a webservice. Like wsdl2php or NuSoap.
Did I understand you correctly that you've created your own test application, and invoked your webservice and everything worked?
I'm still of the mind that you probably need to do a webhandler instead.
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 21, 2010 03:09 PM|LINK
An interesting idea, but I have never created a webhandler before. I need to have something that can accept an XML file through a post and after parsing the XML I will need to return back an XML responce confirming the transmission. I have no problem parsing the XML, and I have no issues returning an XML responce. I felt the WebService process was the best way to approach it.
This WebHandler you have mentioned, how would I go about setting up this to recive the HTTP Post from PHP with an XML in the body of the post?
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 21, 2010 07:56 PM|LINK
well keep in mind I'm not saying your webservice won't work, I'm just saying it may be technically to much for your php people. I could also be a bit bias against PHP people hehe.
Anyways. to answer your question. You would open an existing web application, or create a new one, based on your scenaior. And right click the project and choose "Add new item". And then Choose Generic Handler. The file type for these is .ashx. Rename it to something appopriate...like XmlReciver.ashx.
Handlers can be used to input and output all sorts of things....you can treat it like a normal web page, and access Request parameters...the site can then post the xml string as a url parameter...for instance
http://mywebsite.com/XmlReciever.ashx?xmlString=<node><val>stuff</val></node>
And then you can output the response appropriately. You'd most likely be able to take whatever code you had for your webservice already and put it in the handler, or even just have your handler call your webservice.
Brian
Developer