C# & PHP: Simple example of PHP Web Service used by C# - c#

Could anyone give me a small and simple example of how to do this? Or some good pointers on how to get started.
I would like to create a C# client that can send a file or some text or xml or whatever, to a web service or something similar written in PHP, where the PHP Web Service stores it in a file or a database or something like that. Just not sure how to get started.
I guess the first step would be to create the php web service. And then it perhaps would be quite easy to use it in C#, since I could probably pretty much use the "Add Web Reference" button in vs and then go from there?

You can take a look at this tutorial showing how to develop a web service using php. The .NET client will be pretty straightforward as you mentioned.

I'm not versed in the C# aspect of your question, which you intend to be the consumer. But if you don't mind using a library to expedite the process of getting the webservice up and running, you can set one up very quickly using Zend Framework. Check out the documentation for setting up a Zend_Rest_Server.

Just a thought... if the service only has to support simple operations like "upload a file", perhaps avoid WSDL all together? I assume PHP can handle raw requests - so you can use the oh-so-complex .NET client:
using (WebClient client = new WebClient())
{
client.UploadFile("http://some/upload.php", "foo.bar");
client.UploadString("http://some/upload.php", "some text");
}
etc. Likewise, you can often easily use POX / REST without the complexity of a formal web-service contract. The above code just does a simple HTTP request with the file-contents/string in the body.

you are right. all you need to do is to create a simple web service in PHP, which accepts the request/xml/file and then stores it in a database. then you can use the webservice using any technology, C# for sure.
in order to write a web service in PHP, I think it is better to choose your webservice type in the first step. it can be a REST web service, or SOAP, or XML-RPC. it depends on the level of complexity of your application.
if your application is as simple as just throwing a string to the webservice or a file URL, so then the webservice can store that string, or fetch the file from the URL and stores it in database, I recomment REST. because it is simpler. as simple as just writing a simple PHP script that uses it's HTTP parameters as input.
but incase you want it to be more secure or have more complex needs, It is easy to have SOAP services in PHP. if you wanted to work with SOAP, PHP has an extension (php-soap) which you can install and use the built-in functionality of PHP-SOAP. if you are using an older version of PHP that does not support the extension, or your application will be hosted where php-soap is not installed, there is pure PHP implementaion of SOAP protocol, named nusoap. it is open source and works very well.
http://sourceforge.net/projects/nusoap/

I have made work in PHP NuSOAP webservice and my C# mobile client fetching data from web services.Below is the link
http://khanmubeen.wordpress.com/2010/11/18/web-services-with-php-nusoap-c-mobile-client/
In case you like to know more from me welcome to inbox me at mubeen44us at gmail.com

Related

How do I implement WebSockets from scratch with the .NET 4 Framework (and nothing else)?

Ok I want to build a simple chat app where people can go a url, type in a name and a message and click submit and it will basically show that message to everyone that is current connected.
Firstly i would like to state i've had zero experience in sockets programming and the like. I'm simply a web 2.0 person building websites with css/html/js/ajax and backend i have asp.net on vb and sql server for database.
The many tutorials i've read linked me to http://superwebsocket.codeplex.com/
I've downloaded it, but im totally lost. i can't get the samples working and i don't even know what to run.
So basically coming from an ajax background, i was wondering why do we even need to download any additional stuff to do web sockets? I mean in ajax i can simply create a asd.aspx file and use Response.Write(text) (text based on the input which are available through dissecting the url) and voila, the server side is done, all that's left is just to create new XMLHttpRequest and stuff in the client side.
So ok I'm not worried about the client side part of Web Sockets. but the server side part of web sockets is just difficult. so in the client side i have this: ws://localhost:8080/websocket. Is it true that it will work if is also an .aspx file as such: ws://localhost:8080/websocket.aspx ?
I'm wondering so how do i continue from here? in Ajax i will supply parameters from client in the url as such: page.aspx?a=1&b=2 and do output in the server using Response.Write it's all clear but how do we do it in web sockets?
I mean of course i do not demand a full explanation with a forum reply but if someone could link me to a tutorial/book that actually does explain these stuff it would be great.
Microsoft's implementation has a full chat client sample for both HTML5 and pure C#.
http://html5labs.interoperabilitybridges.com/prototypes/websockets/websockets/download
I'm guessing this implementation is what would end up in ASP.NET and .NET framework so I'm using it because of that.

silverlight process on client side

i am a php developer, not knowing much about silverlight, i am working on a project which needs to process request on client browser, like post httprequests and process them, its a auto directory submitter, can it be done in silverlight application?
i want the user to open the silverlight application, which will submit the post request from client side, and also process for success and failure.
is it possible?
please guide me.
thank you
When you run a silverlight application, you basically download a .xap file (with dlls inside). Those are executed on your machine. I'm no PHP expert but I seem to recall that PHP is executed server-side - so now you know the difference.
In order to communicate with the server you can use one of the popular methods :
use a WCF Webservice
use a WCF Ria WebService
use a WCF REST Webservice
use Sockets
I'm not sure but I think that using a WebClient object is also possible with a POST verb (you'd need to look it up though).
You can access silverlight.net's learning section for some good videos about using WCF services or hand-on labs. I'd also recommend Matthew McDonald's Pro Silverlight (3 or 4) books, those have some good socket examples.
Hope that helps.
Regards

C# + PHP in the same application?

What im trying to do is a little different, im wondering, if its possible to create sorts of an interface, so that if a particular function is called in php (stand alone), than the arguments will be forwarded to a method in C#, and vice versa.
Depends of course on what kind of data you want to exchange, if the applications are on the same server or on two different ones etc.
I did briding between PHP and C# in some of my web based projects. What I did: create an ASP.NET MVC project which exposes a RESTful API. The methods exposed by this API are then called from PHP via HTTP (using CURL). I used JSON as a data exchange format to pass data from PHP to C# and back again. This worked good as the two applications were on different servers.
I could also imagine some kind of socket server. E. g. a background process written in C# is listening on some port, and then you connect to it via PHP´s socket functions. I did something like this to connect PHP and Java. The Java app ran as a demon process on port XXXX and was a wrapper around Apache FOP. I used PHPs socket functions to pass XML and XSLT to the Java demon which then used Apache FOP to transform the data into a pdf and returned that via the socket connection back to PHP which in turn sent the PDF file to the client requesting the page.
There are probably some other approaches, but these were my experiences so far in connecting two different technologies together.
EDIT: as an aside: PHP on a windows webserver using IIS was really not that nice to work with. Sometimes strange errors occured or certain permission related errors that were not easy to resolve. YMMV though.

How to send data from local PC to Google-app-engine application?

I have to write client program in C# that have to take some data from DB and sent it to my Google application(Java). How can I do that? What is the best way to do that?
It'll be great if there be some code example in answers.
You can put your data in JSON format and send it with server request, but I`m not sure does JAVA support working with JSON.
You need to create a web service in your app engine app that would take post data and consume it.
Preferably Use a web service framework otherwise you will have to do a lot of xml parsin yourself, which is baaed. mmmkay
Now I dont know if ur using py or java, but do look for a web service framework in ur language. mmkay

Will this web service accept both raw xml and an object?

We have a web service that provides auto insurance quotes and a company that provides an insurance agency management system would like to use the web service for thier client but they want to pass the web service raw xml instead of using the wsdl to create a port, the object the service expects and calling the web method.
The web service has performed flawlessly by creating an object like so
com.insurance.quotesvc.AgencyQuote service = new com.insurance.quotesvc.AgencyQuote();
com.insurance.quotesvc.QuotePortType port = service.getQuotePortType();
com.insurance.quotesvc.schemas.request.ACORD parameter = null;
Then create initialize the request object with the other objects that make up the response.
parameter = factory.createACORD();
parameter.setSignonRq(signOn);
parameter.setInsurancesSvcRq(svcRq);
And send the request to the web service.
com.insurance.quotesvc.schemas.response.ACORD result = null;
result = port.requestQuote(parameter);
By doing that I am able to easily marshall the request and the result into an xml file and do with them as I wish.
So if a client was to send the web service via an http post as raw xml inside of a soap envelope. Would the web service be able to handle the xml without any changes being made to the web service or would there need to be changes made to the web service in order for it to handle a request of that type?
The web service is a JAX_WS and we currently have both Java and C# clients consuming the web service using the method described above but now there is another client who wants to send raw xml inside of a soap envelope instead of creating the objects. I feel pretty sure that they will be making the call to the web service using vb.
I'm sure I'm missing something obvious but it is eluding me at the moment and any help is greatly appreciated.
I think you'd need separate URLs to handle this situation. You'd still map your WSDL and its endpoint as you're doing. But then you'd need to configure a second, separate URL that would have a servlet that accepted an encoded XML stream from the HTTP POST and dealt with that separately.
In theory, it should be possible to hand-build XML that is indistinguishable from the XML that is created by a conventional WS client.
In practice, getting this right in all of the edge cases could be rather difficult. And if they (the clients who send raw XML to your service) get it wrong, they are liable to get a lot of obscure errors ... and you may need to help them with diagnosing these errors.
In the worst case, malformed messages might impact on your system's performance. But one would hope that the WS middleware layers and your application are hardened against the effects of malformed requests.
In short, #duffymo's approach of creating a second API is less risk for you, though the cost is more up-front work for you. But the simplest approach would be to just say "No!".
Should be no problem since your wsdltojava and wsdltocsharp will just do that for you behind the scenes. As long as they follow the contract set out by the WSDL.
But it is a lot of work doing it manualy and completely unneccesary since there is also a wsdltovb thing which should be eassier for them. ANd they have to do it all over again when you change something on your side.
They are just reinventing the wheel.

Categories