473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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


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
4 12266
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Hatmaker | last post by:
I have begun experimenting with web services, and I created some simple web services in C# and was able to install them with IIS and create an equally simple C# client to consume them. My next...
4
by: John Bailo | last post by:
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...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
0
by: Vince | last post by:
Hi, I wrote a windows service with a socket that receives files and once a file has been received it tries to execute it. My problem comes from execution because nothing happens. I have...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
7
by: e2wugui | last post by:
thread1: while 1: buf = s.read() process(buf) thread2: while 1: buf = getdata() s.write(buf)
3
by: Donald | last post by:
I need to consume a web service. Here's my situation: 1) I need to consume a web service from an IBM AIX server/Web Sphere. 2) The IBM AIX Server is not on the same network as the IIS server...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
6
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.