HttpWebRequest hwRequest;
HttpWebResponse hwResponse;
System.IO.StreamReader sReader;
XmlDocument xmlDoc = new XmlDocument();
int iTimeout = 1;
System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");// Pipes the stream to a higher level stream reader with the required encoding format.
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string strXMLRequest = @"" +
@"
@" xmlns:eb='http://www.ebxml.org/namespaces/messageHeader' xmlns:xlink='http://www.w3.org/1999/xlink' " +
@" xmlns:xsd='http://www.w3.org/1999/XMLSchema'> " +
@"
@"
@"
@" xmlns:xs='http://www.w3.org/2001/XMLSchema' " +
@" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' PrimaryLangID='en-us' AltLangID='en-us'> "+
@"
@"
@" "+
@"
@"
@"
@"
@"
@"
@"
@" "+
@"
@"
@"
@" "+
@" "+
@"
@"
@"
@" "+
@"
@"
@"
@" "+
@" "+
@" "+
@"
@"
@"
@"
@"
@" "+
@" "+
@" "+
@" "+
@"
@" "+
@"
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(strXMLRequest);
string strWebServiceURL = "http://XYZ.com/default1.aspx";
hwRequest = (HttpWebRequest)HttpWebRequest.Create(strWebServiceURL);
hwRequest.Headers.Add("SOAPAction", "http://test.abc.com/soap/testing/TestWebservice/message");
hwRequest.ContentType = "text/xml; charset=utf-8";
hwRequest.Accept = "text/xml";
hwRequest.Credentials = CredentialCache.DefaultCredentials;
hwRequest.Method = "POST";
hwRequest.Timeout = iTimeout * 1000;
//hwRequest.ContentLength = soapEnvelopeXml.OuterXml.Length;;
using (Stream stream = hwRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
hwResponse = (HttpWebResponse)hwRequest.GetResponse();
sReader = new StreamReader(hwResponse.GetResponseStream());
string strXMLReply = sReader.ReadToEnd();
sReader.Close();
xmlDoc.LoadXml(strXMLReply);
Response.Write(xmlDoc.OuterXml);
plz see it
it is not working plz tell me
vipin sainiPosted Sep 17, 2010, 5:48 AM
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
this is the stack trace
vipin sainiPosted Sep 17, 2010, 4:25 AM
this is the error now on the position
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
it means i post my request on server
Posted Sep 17, 2010, 3:28 AM
If you are not getting the response may be the server side is not accepting stream of bytes...
Can u be more specific on ur requirement and also the website for which u have to access the web service.....
With Regards
P.Krishna Prasad
vipin sainiPosted Sep 17, 2010, 3:16 AM
post SOAP request message as an attachment for the desired response now i am use ur process but responce is not getting
Posted Sep 17, 2010, 3:11 AM
first of all i have a small question for u....Why do u want to post and get response for a soap request...
Soap is a protocol used to transfer text as u may know...If you are looking for webservice...
Just add web reference of there site in your case "ww.xyz.com" and use their web methods...
If you are looking for webposting then...in your case
just add the contents u have in string strXMLRequest in a text document and save it as request.xml in c:
add the following namespaces in your application
using System.Net;
using System.Web;
using System.IO;
using System.Data;
using System.Xml;
Then..add the following peice of code in your application
string Output = "";
byte[] bytes = Encoding.ASCII.GetBytes("c:\\request.xml");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://XYZ.com/default1.aspx");
//request.Credentials=
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
{
using (StreamReader responseStream =
new StreamReader(webResponse.GetResponseStream(), Encoding.ASCII))
{
Output = responseStream.ReadToEnd();
MessageBox.Show(Output);
}
}
so the concept is ur sending the xml file as a byte stream to the site u mentioned and getting a a response which u save it in a string called output and displaying it in a messagebox......
Hope i made my self clear.....
vipin sainiPosted Sep 17, 2010, 1:55 AM
vipin sainiPosted Sep 17, 2010, 1:49 AM
Posted Sep 17, 2010, 1:33 AM
just a small tweak in your code....
string Output = "";
byte[] bytes = Encoding.ASCII.GetBytes("d:\\general\test.xml");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://XYZ.com/default1.aspx");
//request.Credentials=
request.Method = "POST";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
}
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
{
using (StreamReader responseStream =
new StreamReader(webResponse.GetResponseStream(), Encoding.ASCII))
{
Output = responseStream.ReadToEnd();
MessageBox.Show(Output);
}
}
Here the file name is the path of the xml file..In your case wat have as a string.save it as an xml file and athhach the path of it...it would be simpler..
Hope i made myself clear..Feel free to ask ...
IF u like the answer don't forget to mark it as right....