By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

Can I consume a web service with a Socket in c# ?

P: n/a

I wrote a .NET/c# webservice which I then needed to consume from java server
pages.

The simplest ( and best ) solution I found, was some code to open a socket,
and send a SOAP message directly to it...constructing the SOAP message with
a class that builds the string.

Then I parse the return soap message for the result.

Now I wonder, can I do the same thing in a c# client. All I want to do is
open a Socket to the web service, send the SOAP message and retrieve the
result as a string.

Can I do this in c#:

Server = IPAddress;
Socket s = new Socket(Server, 80);
OutputStream os = socket.getOutputStream();
PrintWriter out1 = new PrintWriter(socket.getOutputStream, true);

And then send a soap message to it with:

out1.println("POST " + WebservicePath + " HTTP/1.1");
out1.println("Host: " + ServiceName);
....

and so on...

This is where I found that java code ( it's in an applet, but I converted it
to use in a jsp page ):

http://www.codeproject.com/soap/WSfromJava.asp
--
http://www.texeme.com
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You can definitely use sockets to write and consume web services, but why not
to use web services support that is built into .NET and J2EE? It takes very
little code to consume or create a web service compared to using Sockets.

"John Bailo" wrote:

I wrote a .NET/c# webservice which I then needed to consume from java server
pages.

The simplest ( and best ) solution I found, was some code to open a socket,
and send a SOAP message directly to it...constructing the SOAP message with
a class that builds the string.

Then I parse the return soap message for the result.

Now I wonder, can I do the same thing in a c# client. All I want to do is
open a Socket to the web service, send the SOAP message and retrieve the
result as a string.

Can I do this in c#:

Server = IPAddress;
Socket s = new Socket(Server, 80);
OutputStream os = socket.getOutputStream();
PrintWriter out1 = new PrintWriter(socket.getOutputStream, true);

And then send a soap message to it with:

out1.println("POST " + WebservicePath + " HTTP/1.1");
out1.println("Host: " + ServiceName);
....

and so on...

This is where I found that java code ( it's in an applet, but I converted it
to use in a jsp page ):

http://www.codeproject.com/soap/WSfromJava.asp
--
http://www.texeme.com

Nov 21 '05 #2

P: n/a
csharpcomputing.com wrote:
You can definitely use sockets to write and consume web services, but why
not to use web services support that is built into .NET and J2EE? It takes
very little code to consume or create a web service compared to using
Sockets.
For a hard coded web method yes.

But for programmatic control of webservices -- not at all.

Say I want to write a generalized class for handling multiple services and
methods.

I can do that with the soap method below very effectively --- adding
parameters as vectors to the SOAP message.


"John Bailo" wrote:

I wrote a .NET/c# webservice which I then needed to consume from java
server pages.

The simplest ( and best ) solution I found, was some code to open a
socket, and send a SOAP message directly to it...constructing the SOAP
message with a class that builds the string.

Then I parse the return soap message for the result.

Now I wonder, can I do the same thing in a c# client. All I want to do
is open a Socket to the web service, send the SOAP message and retrieve
the result as a string.

Can I do this in c#:

Server = IPAddress;
Socket s = new Socket(Server, 80);
OutputStream os = socket.getOutputStream();
PrintWriter out1 = new PrintWriter(socket.getOutputStream, true);

And then send a soap message to it with:

out1.println("POST " + WebservicePath + " HTTP/1.1");
out1.println("Host: " + ServiceName);
....

and so on...

This is where I found that java code ( it's in an applet, but I converted
it to use in a jsp page ):

http://www.codeproject.com/soap/WSfromJava.asp
--
http://www.texeme.com


--
http://www.texeme.com
Nov 21 '05 #3

P: n/a
byte [] sendArray;//put your data here
TcpClient tcpClient=new TcpClient();
tcpClient.Connect(this.ipAddress,this.portNumber);
NetworkStream networkStream=tcpClient.GetStream();
if(networkStream!=null && networkStream.CanWrite)
{
try
{
networkStream.Write(sendArray, 0,sendArray.Length);
}
....
Hope this helps.
Aleksey Nudelman
http://csharpcomputing.com

"John Bailo" wrote:
csharpcomputing.com wrote:
You can definitely use sockets to write and consume web services, but why
not to use web services support that is built into .NET and J2EE? It takes
very little code to consume or create a web service compared to using
Sockets.


For a hard coded web method yes.

But for programmatic control of webservices -- not at all.

Say I want to write a generalized class for handling multiple services and
methods.

I can do that with the soap method below very effectively --- adding
parameters as vectors to the SOAP message.


"John Bailo" wrote:

I wrote a .NET/c# webservice which I then needed to consume from java
server pages.

The simplest ( and best ) solution I found, was some code to open a
socket, and send a SOAP message directly to it...constructing the SOAP
message with a class that builds the string.

Then I parse the return soap message for the result.

Now I wonder, can I do the same thing in a c# client. All I want to do
is open a Socket to the web service, send the SOAP message and retrieve
the result as a string.

Can I do this in c#:

Server = IPAddress;
Socket s = new Socket(Server, 80);
OutputStream os = socket.getOutputStream();
PrintWriter out1 = new PrintWriter(socket.getOutputStream, true);

And then send a soap message to it with:

out1.println("POST " + WebservicePath + " HTTP/1.1");
out1.println("Host: " + ServiceName);
....

and so on...

This is where I found that java code ( it's in an applet, but I converted
it to use in a jsp page ):

http://www.codeproject.com/soap/WSfromJava.asp
--
http://www.texeme.com


--
http://www.texeme.com

Nov 21 '05 #4

P: n/a
csharpcomputing.com wrote:
byte [] sendArray;//put your data here
TcpClient tcpClient=new TcpClient();
tcpClient.Connect(this.ipAddress,this.portNumber);
NetworkStream networkStream=tcpClient.GetStream();
if(networkStream!=null && networkStream.CanWrite)
{
try
{
networkStream.Write(sendArray, 0,sendArray.Length);
}
...
Thanks, man!

You made my weekend that much easier!

Hope this helps.
Aleksey Nudelman
http://csharpcomputing.com

"John Bailo" wrote:
csharpcomputing.com wrote:
> You can definitely use sockets to write and consume web services, but
> why not to use web services support that is built into .NET and J2EE?
> It takes very little code to consume or create a web service compared
> to using Sockets.


For a hard coded web method yes.

But for programmatic control of webservices -- not at all.

Say I want to write a generalized class for handling multiple services
and methods.

I can do that with the soap method below very effectively --- adding
parameters as vectors to the SOAP message.

>
> "John Bailo" wrote:
>
>>
>> I wrote a .NET/c# webservice which I then needed to consume from java
>> server pages.
>>
>> The simplest ( and best ) solution I found, was some code to open a
>> socket, and send a SOAP message directly to it...constructing the SOAP
>> message with a class that builds the string.
>>
>> Then I parse the return soap message for the result.
>>
>> Now I wonder, can I do the same thing in a c# client. All I want to
>> do is open a Socket to the web service, send the SOAP message and
>> retrieve the result as a string.
>>
>> Can I do this in c#:
>>
>> Server = IPAddress;
>> Socket s = new Socket(Server, 80);
>> OutputStream os = socket.getOutputStream();
>> PrintWriter out1 = new PrintWriter(socket.getOutputStream, true);
>>
>> And then send a soap message to it with:
>>
>> out1.println("POST " + WebservicePath + " HTTP/1.1");
>> out1.println("Host: " + ServiceName);
>> ....
>>
>> and so on...
>>
>> This is where I found that java code ( it's in an applet, but I
>> converted it to use in a jsp page ):
>>
>> http://www.codeproject.com/soap/WSfromJava.asp
>>
>>
>> --
>> http://www.texeme.com
>>


--
http://www.texeme.com


--
http://www.texeme.com
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.