Susan - desperately seeking ...

S

Susan Baker

Hi Guys (and girls),

I am in a bit of a bind. I'm looking for a simple "proof of concept" C#
app (WinForm OR console) that sends a web request to a simple PHP script
and receives BINARY data back from the PHP script. Binary data is
necessary because I want to be able to send files as well as compressed
(zipped) data.

The example PHP script can ofcourse, simply make up some dummy data and
send it to the C# app. I have tried desperately over the last few weeks
to locate such an example, but have been unsuccesful so far. I would be
most grateful for anyone who can help.
 
C

Chance Hopkins

Why don't you just post the specs then someone can code it for you, zip it
and post it somewhere for you to download.
 
S

Susan Baker

Chance said:
Why don't you just post the specs then someone can code it for you, zip it
and post it somewhere for you to download.

Hi Chance, Thanks for the quick response. I have sent you the specs as
well as my private email. I look forward to hearing from you.

Regards,

Sue
 
M

Mladen Gogala

Hi Guys (and girls),

I am in a bit of a bind. I'm looking for a simple "proof of concept" C#
app (WinForm OR console) that sends a web request to a simple PHP script
and receives BINARY data back from the PHP script. Binary data is
necessary because I want to be able to send files as well as compressed
(zipped) data.

The example PHP script can ofcourse, simply make up some dummy data and
send it to the C# app. I have tried desperately over the last few weeks
to locate such an example, but have been unsuccesful so far. I would be
most grateful for anyone who can help.

Susan, why don't you install PEAR MAIL_Mime package and send the binary
data by email? What you want is, basically, to send data from PHP script
to an application. That is usually done through messaging/queueing
applications like MQSeries (part of WebSphere) or Tibco's RendesVous.
In the absence of such complex queueing systems, an ordinary email
might do the trick. It can be configured and played with, to make sure
that the mail ends up on the right address.
Another solution for two diverse system to communicate is to share a
database. Binary data would then be uploaded as a BLOB field and the
row pointer would be passed to the client.
 
C

Chung Leong

C# is not my forte but here's a very basic example:

private void button1_Click(object sender, System.EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://localhost/file.php");
request.Headers["Something"] = "Dingo";
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Stream hs = response.GetResponseStream();
FileStream fs = new FileStream("C:\\test.gif", FileMode.Create,
FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
BinaryReader br = new BinaryReader(hs);
Byte[] buffer;
do {
buffer = br.ReadBytes(1024);
bw.Write(buffer);
} while(buffer.Length > 0);
bw.Close();
br.Close();
}


The PHP script just dumps a gif file into the output:

<? readfile("dingo.gif"); ?>

I suggested using the HTTP headers to pass parameters in another post,
as it's fairly easy to set their values. In the PHP script, the
"Something" header will become $_SERVER['HTTP_SOMETHING']. The PHP
script can set response header using the header() function:

header("Dingo: Ate my wienerschnitzel!");

Which then is accessible through HttpWebResponse.Headers["Dingo"].
 
J

Jon Skeet [C# MVP]

Mladen Gogala said:
Susan, why don't you install PEAR MAIL_Mime package and send the binary
data by email? What you want is, basically, to send data from PHP script
to an application. That is usually done through messaging/queueing
applications like MQSeries (part of WebSphere) or Tibco's RendesVous.
In the absence of such complex queueing systems, an ordinary email
might do the trick. It can be configured and played with, to make sure
that the mail ends up on the right address.
Another solution for two diverse system to communicate is to share a
database. Binary data would then be uploaded as a BLOB field and the
row pointer would be passed to the client.

That all sounds very complicated, considering that from all we've been
told, a simple web solution is a perfectly good (and *much* easier)
solution. After all, a browser requesting an image conforms exactly to
the situation Susan specified. There's no need to get message queues,
email or a database involved.
 
J

Jon Skeet [C# MVP]

Susan Baker said:
Hi Guys (and girls),

I am in a bit of a bind. I'm looking for a simple "proof of concept" C#
app (WinForm OR console) that sends a web request to a simple PHP script
and receives BINARY data back from the PHP script. Binary data is
necessary because I want to be able to send files as well as compressed
(zipped) data.

The example PHP script can ofcourse, simply make up some dummy data and
send it to the C# app. I have tried desperately over the last few weeks
to locate such an example, but have been unsuccesful so far. I would be
most grateful for anyone who can help.

I'd suggest splitting your problem into two parts:

1) Write a PHP script which can spit back the dummy data. (You can test
this with a web browser)

2) Write a C# client app which can download data from an arbitrary URL.
(You can test this with a web server with a dummy file on.)

If you get stuck on either part, please post on the appropriate group
with how far you've got.
 
P

Peter Fox

Following on from Jon Skeet's message. . .
I'd suggest splitting your problem into two parts:

Good idea

RFC 2616 tells you how to compose HTTP requests and interpret the HTTP
responses. (Not surprisingly, that's what PHP uses for all it's web
work.)
 
J

Jon Skeet [C# MVP]

Peter Fox said:
Good idea

RFC 2616 tells you how to compose HTTP requests and interpret the HTTP
responses. (Not surprisingly, that's what PHP uses for all it's web
work.)

Fortunately, that's not really required in C# - .NET provides plenty of
infrastructure for making HTTP requests very easily.
 
M

Mladen Gogala

That all sounds very complicated, considering that from all we've been
told, a simple web solution is a perfectly good (and *much* easier)
solution. After all, a browser requesting an image conforms exactly to
the situation Susan specified. There's no need to get message queues,
email or a database involved.

I don't know a squat about .NOT so I attacked the most general case.
I read some of the solutions and, at least from the PHP side, they're
trivial. Of course, I'd prefer Chung to express himself in some of humanly
readable languages instead of C#.
 
J

Jon Skeet [C# MVP]

Mladen Gogala said:
I don't know a squat about .NOT so I attacked the most general case.

Fair enough. I'd suggest that those in the PHP newsgroup start at the
PHP side, and those in the C# group start on the C# side.
I read some of the solutions and, at least from the PHP side, they're
trivial.

Good - likewise on the C# side, to be honest. I suspect the problem was
that the OP wasn't sure where to start. Hopefully the suggestion of
"faking" each side while developing the other will have helped.
Of course, I'd prefer Chung to express himself in some of humanly
readable languages instead of C#.

Please, let's not start a flame war. I doubt whether you're any more
likely to persuade me that PHP is superior to C# than I am to persuade
you that C# is superior - nor am I particularly interested in trying to
do that anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top