Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to manually program sending / reciving of SOAP to/from WebServices

0 views
Skip to first unread message

Ashish

unread,
May 22, 2003, 9:02:38 AM5/22/03
to
Hi Friends,
I am involved in an academic project where I need to code a project that
students can look at and learn how to manually:
1. Create SOAP Messages.
2. Send it to a java webservice via a .net application.
3. Recieve reply from java webservice.
I know how to do this by adding references in C# project, but that would
fail the whole purpose of the project. Can someone tell me good resources in
.net that addresses the above mentioned issues.
Regards
Ashish


Brett Keown [MSFT]

unread,
May 22, 2003, 10:04:51 PM5/22/03
to
Hi Ashish,

I will send this on to our Xml Support Team and see if they can come up with something for you. Thanks for your patience!

Brett Keown
Microsoft Developer Support
bre...@nospam.microsoft.com

To email me directly, please remove the "nospam" from my email address.

This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.

Ashish

unread,
May 23, 2003, 10:38:34 AM5/23/03
to
Thanks Brett,
I think I should clerify that by the term "manually" I mean programatically.
I am sure you have figured this out, but I just wanted to again clarify it..
Really appriciate your help and looking forward to hear from you.
Regards
Ashish
"Brett Keown [MSFT]" <bre...@online.microsoft.com> wrote in message
news:vvhof#MIDHA...@cpmsftngxa06.phx.gbl...

Brett Keown [MSFT]

unread,
May 23, 2003, 1:37:42 PM5/23/03
to
Hi Ashish,

Here is the answer I received from the support team:

The easiest way to do this is via a HTTPWebClient or HTTPRequest object.
The basic idea is to create a message in SOAP format, and using a POST
method, would send it up and receive a stream of data back. Since the soap
message is basically text, building it shouldn’t be too hard, as long as
you know the format. After the soap text message is created, you can then
post it to the web service via the above client classes

Here are some articles from WebCasts

324811 Support WebCast: Microsoft ASP.NET: Advanced XML Web Services Using
http://support.microsoft.com/?id=324811

Serialization allows you to take a class and convert it into an Xml String
323503 WebCast: XML Serialization and Sample Code
http://support.microsoft.com/?id=323503

There are many other soap resources to understand the various formats, but
we have the SOAPFormatter class which can help build the soap message.
They the basic client class is either the HTTPWebClient/HTTPRequest
classes. You may need credentials to hit the webservice so you may want to
look into the Credentials class.

Hope that helps you Ashish. If not, reply back with your addistional
requirements and I will do what I can to assist you further.

Brett Keown
Microsoft Support
bre...@online.microsoft.com

Ashish

unread,
May 24, 2003, 2:38:22 PM5/24/03
to
Hi Brett,
Thanks for your help. I have come up with the following code, but I always
get an exception when debugger reaches the GetResponse method. The exception
says: 500 Internal Server Error (I have marked the line that gives the
error). My webservice works good in browser. What could be possible reasons
for this error ?

Thanks
Ashish

Input:
txtServiceURI.Text = http://localhost/TestService/Add.asmx
txtSOAPRequest.Text =
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<A>10</A>
<B>10</B>
</Add>
</soap:Body>
</soap:Envelope>

try

{

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(txtServiceURI.Text);

req.Method = "POST";

req.KeepAlive = true;

byte[] bytes = System.Text.Encoding.UTF8.GetBytes(txtSOAPRequest.Text);

req.ContentLength = bytes.Length;

System.IO.Stream st = req.GetRequestStream();

st.Write(bytes, 0, bytes.Length);

st.Close();

>>>> THROWS >>>>> HttpWebResponse res = (HttpWebResponse)req.GetResponse();

System.IO.Stream st1 = res.GetResponseStream();

System.IO.StreamReader sr = new System.IO.StreamReader(st1,
System.Text.Encoding.UTF8);

string txt = sr.ReadToEnd();

this.txtSOAPResponse.Text = txt;

res.Close();

}

catch (Exception exp)

{

MessageBox.Show(this,exp.Message);

}

"Brett Keown [MSFT]" <bre...@online.microsoft.com> wrote in message

news:Gt4AGIVI...@cpmsftngxa06.phx.gbl...

Ashish

unread,
May 24, 2003, 4:00:09 PM5/24/03
to
I got it. I wasnt adding a custom SOAP header to the request.. when I
performed:
req.Headers.Add ("SOAPAction: http://tempuri.org/Add");

Everything worked fine.. Thanks to all for their help. I really appriciate
the spirit..

Ashish

"Ashish" <a...@hotmail.com> wrote in message
news:e5S9sJGI...@TK2MSFTNGP11.phx.gbl...

Brett Keown [MSFT]

unread,
May 27, 2003, 4:30:56 PM5/27/03
to
Glad we could help.
0 new messages