Tuesday, August 4, 2009

A simple SOAP client

The program is written in C#.

You can find a java client in http://www.cafeconleche.org/books/xmljava/chapters/ch03s05.html

The below code will not work just by copying and executing. If you are familliar with C# will get the idea.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Net;

namespace WWeb
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();

doc.Load(@textBoxIn.Text);

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

req.Headers.Add("SOAPAction", "\"\"");

req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);

richTextBox1.AppendText(r.ReadToEnd());


}

private void buttonIn_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
textBoxIn.Text = openFileDialog1.FileName;
}
}
}

No comments: