473,387 Members | 3,787 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,387 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 16 '05 #1
4 1229
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 16 '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 16 '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 16 '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 16 '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...
2
by: Abeslom via .NET 247 | last post by:
Hi, I am trying to create a simple .NET http-Get client that willconsume a java webservice on a mainframe. If I type the URL forthe webservice in the Browser, the service works and I get theexpected...
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...
0
by: leslie_tighe | last post by:
Hello, I have a set of web services running on Java server that are exposed through axis 1.2.1. I can invoke these services in browser and through a java test client. However, when I try to...
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...
3
by: frustratedcoder | last post by:
I need to consume a web service written in Perl but there is no wsdl file for this service. The perl soap client that can call and consume this web service looks like this (if it helps) #!perl...
2
by: hharry | last post by:
hello all, trying to consume a simple web service using httpwebrequest instead of generating a proxy class. code for simple web service: Imports System.Web.Services ...
3
by: jwpaco | last post by:
I am new to services and I have quite the task. I need a windows service that will, once started, open a socket and listen for client connections. When a connection is made, the client will want...
7
by: GD | last post by:
Hi, I am trying to call a webservice from a windows service application. It works only if I launch the windows service app from VS.Net 2005 (Worked around from Main()) or from a winform test...
3
by: ChristianProgrammer | last post by:
Its been a month and a half now. I have tried to get my WSSF web service to reference a class library that IS a Socket Client. The Socket Client in question runs fine when called by a testing exe....
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.