5

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?

5 Answers 5

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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.

1 Comment

that is a solution as well of course. but how would you... accept that uploaded string and file on "the other side"?
0

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/

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.