I'm retrieving some userdata from a phpbb3 forum through scripts on the server.
My database does not allow for external login, so I have to go through some kind of script.
But, I'd like to know if there is a safe enough way to retrieve this data?
I know how to output some XML with echo statements, but I'm not sure if this is as secure as it should be?
Optimal method would be (psuedo code)
$array['user_id'] = $id;
$array['otherinfo'] = $var
return $array;
if I could somehow read this array with C#, it would be much easier, but I'm not sure how this would work with WebResonses or whatnot.
Any ideas?
You need a web service, that will output your responses in some format that you can parse with C#.
Php and C# are not interoperable, that s why you will need to create a service that you can consume these messages.
First option as I said is to create a web service, that C# code can consume. In this case, your C# code should know what to ask from your php web service, and you will respond to the request, in XML, or JSON or whatever format you want to use within your C# code to parse it.
Another option is to push the data to a web service that uses C#. You need to write a WCF/ Web service, and you can push the data to this service.
I suggest you to give your array output as xml or json. If we take xml as consideration, you can call the php file which gives xml output like this:
XDocument.Load("http://whatever.com/whatever.php");
And ofc you need to add the System.Xml.Linq header to use XDocument class. And also you can pass a hashed key, etc. from query string to validate the requested is coming from your app.
Related
I want to create a proprietary minimal / bare-bone / data-light webservice. I prefer not to use the standard solutions like Restful, WebAPI, SOAP, WCF, etc.
I just want a web server listener that can receive and process 1 UTF8 string (own message format) and respond with 1 UTF8 string as the result.
My question is: can you give me a starting point, by providing a code example of the interface. Of course not the complete implementation.
Data transfer has to be as minimal as possible (no avoidable headers).
NB: Server language has to be .NET. Code example may be in C# or VB.
The most bare-bone thing to create a web service would be an HTTP Handler.
The sample I linked returns HTML but you could send back XML as well (or anything else really, just make sure to return an appropriate Content Type).
The call to your method would be a regular HTTP call of the URL of your Handler.
This is my first time developing this kind of system, so many of these concepts are very new to me. Any and all help would be appreciated. I'll try to sum up what I'm doing as efficiently as possible.
Background: I have a web application running AngularJS with Bootstrap. The app communicates with the server and DB through a web service programmed using C#. On the site, users can upload files and reference them later using direct links. There's no restriction to file type (yet), so just about anything is allowed.
My Goal: Having direct links creates a big security problem for me, since the documents/images are supposed to be private data. What I would prefer to do is validate a user's credentials when the link is clicked, then load the file in the browser using a more generic url path.
--Example--
"mysite.com/attachments/1" ---> (Image)
--instead of--
"mysite.com/data/files/importantImg.jpg"
Where I'm At: Not very far. My first thought was to add a page that sends the server request and receives a file byte stream along with mime type that I can reassemble and present to the user. However, I have no idea if this is possible using a web service that sends JSON requests, nor do I have a clue about how the reassembling process would work client-side.
Like I said, I'll take any and all advice. I'd love to learn more about this subject for future projects as well, but for now I just need to be pointed in the right direction.
Your first thought is correct, for it, you need to use the Response object, and more specifically the AddHeader and Write functions. Of course this will be a different page that will only handle file downloads, so it will be perfectly fine in your JSON web service.
I don't think you want to do this with a web service. Just use a regular IHttpHandler to perform the validation and return the data. So you would have the URL "attachments/1" get rewritten to "attachments/download.ashx?id=1". When you've verified access, write the data to the response stream. You can use the Content Disposition header to set the file name.
I am going to have XML output from web service. in fact, I write a method in web service that returns a first of objects, now I want to have this list of objects in XML format in client side.
Does web service produce XML output?
If yes, how can I get XML in client side?
I don't want to write XML document in web service
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
return
<string>Hello World</string>
Please help me
I'm not entirely sure your question makes sense:
does web service produce XML output?
It can pretty much return whatever you like. You can make it return raw xml, you can make it return XmlNode-objects, or something similar.
This is what confuses me:
I don't want to write XML document in web service
Does this mean you don't want to build the XML-object at all, on the server side? If so, it will be up to your client to create the xml. How you can do that obviously depends on what data you are returning. I don't think there is any "magic" in c# that will do this for you automatically, just because it is a response from a WS.
Regarding your specific issue, you can find some guidance here.
When defining the details of your data contract and your WCF endpoint, you can decide the exact communication protocol and the form used to return your results. There, you could set the options of using REST or SOAP (see this for more) or returning results as JSON or raw data.
Hope I helped!
So I've been doing research and I know that I will need to create a aspx script and run a query in aspx. Then convert the data into XML format for objective C to parse through it.
My question is can anyone elaborate a little bit more? I have little knowledge of xml and aspx.
For example example.com/test.aspx queries a user table, then I can get it to display on the browser. But what next? Convert it to xml format? Then how would my app retrieve the xml?
Thanks
Check out asp.net web api - this covers how to expose CRUD operations. The server web-api would either use ado.net to query the database directly and populate objects that then get serialized over the wire or you could use something like the entity framework or something like NHibernate to get the objects from the DB.
In iOS/Cocoa objective-c you would use the NSURLConnection to make a request to the web api server.
If the server is configured to return XML (your request sets accept header to application/xml), then in objective-c you would use NSXMLParser.
But, the more web friendly/modern approach is the http server could return json (request sets accept header to application/json) as the data and in iOS 5 and beyond, there's a JSON parser: http://www.raywenderlich.com/5492/working-with-json-in-ios-5
Where can I find the RAW/object data of a SOAP request in C# when using WebServices.
Can't find it anywhere. Shouldent it be available in the HttpContext.Current.Request object ?
Shouldent it be available in the HttpContext.Current.Request object ?
No, it shouldn't.
What are you trying to accomplish? If you just want to see that data so you can log it, or as an aid to debugging, then see the example in the SoapExtension class. It's a working sample of an extension that can log input and output as XML. I've used a modified version of it myself.
If you're just looking to debug your web service, then you can install Fiddler, and that allows you to inspect the data sent to and from your web service.
It sounds like you're going to have to go lower level on your implementation if you want to see the raw XML. Check out the generic handler (ASHX extension). This will allow you to deal with the request/response streams directly. It's very low level, but gives you full control over the service lifecycle.
I found
Request.Params[null]
refers to the RAW data posted to the page in C# ASP.NET.