Link to home
Create AccountLog in
Avatar of Howard Katz
Howard KatzFlag for United States of America

asked on

How to post an soap xml file to a webservice and get the reponse

Hello Experts,

I am going a bit mad and I need your help.  My environment is Visual Studio 2010, asp.net, c#.

I am building a Soap Envelope and then I need to post it to a remote web service and get the response.

The web service is

https://stage.e-verify.uscis.gov/WebService/EmployerWebServiceV23.asmx?op=EmpGetCitizenshipStatusCodes

and the response object goes to this method.

EmpGetCitizenshipCodesResp

Here is what I have.  I build the xmlString.                  

DateTime thisMoment = DateTime.UtcNow;
 HttpWebRequest request = HttpWebRequest.Create("https://stage.e-verify.uscis.gov/WebService/EmployerWebServiceV23.asmx?op=EmpGetCitizenshipStatusCodes") as HttpWebRequest;

                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";

                Encoding e = Encoding.GetEncoding("iso-8859-1");

                string xmlString = "<?xml version='1.0' encoding='utf-8'?>";
                xmlString += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ";
                xmlString += "xmlns:xsd='http://www.w3.org/2001/XMLSchema' ";
                xmlString += "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
                xmlString += "<soap:Header>";
                xmlString += "<wsse:Security soap:mustUnderstand='1' xmlns:wsse='http://schemas.xmlsoap.org/ws/2002/04/secext'>";
                xmlString += "<wsse:UsernameToken>";
                xmlString += "<wsse:Username>HK1299</wsse:Username>";
                xmlString += "<wsse:Password Type='type info'>HK#$19s</wsse:Password>";
                xmlString += "<wsse:Nonce>124857285714</wsse:Nonce>";
                xmlString += "<wsu:Created xmlns:wsu='http://schemas.xmlsoap.org/ws/2002/04/secext'>" + thisMoment + "</wsu:Created>";
                xmlString += "</wsse:UsernameToken>";
                xmlString += "</wsse:Security>";
                xmlString += "</soap:Header>";
                xmlString += "<soap:Body>";
                xmlString += "<EmpGetCitizenshipStatusCodes xmlns='https://www.vis-dhs.com/EmployerWebService/' />";
                xmlString += "</soap:Body>";
                xmlString += "</soap:Envelope>";

                XmlDocument doc = new XmlDocument();
                XmlNamespaceManager objNM = null;

                objNM = new XmlNamespaceManager(doc.NameTable);
                objNM.AddNamespace("wsse", "http://www.w3.org/2001/12/soap-envelope");
                objNM.AddNamespace("wsu", "http://www.w3.org/2001/12/soap-envelope");

                doc.LoadXml(xmlString);
                string rawXml = doc.OuterXml;

After this, I have no idea what is happening.  How do I post what I just created and get the response.

Thank you so much if you can help

Howard


                System.Xml.XmlDocument SendingXmlDoc = new System.Xml.XmlDocument();
                SendingXmlDoc.LoadXml(xmlString.ToString());

                System.Xml.XmlDocument response = new System.Xml.XmlDocument();
                string responseMsg = response.ToString();

                string requestText = string.Format("myxmldata={0}", HttpUtility.UrlEncode(rawXml, e));
                Stream requestStream = request.GetRequestStream();
                doc.Save(requestStream);
                StreamWriter requestWriter = new StreamWriter(requestStream, e);
                requestWriter.Write(requestText);
                requestWriter.Close();
                requestStream.Close();



Here is what I have so far.  
Avatar of Manoj Patil
Manoj Patil
Flag of India image

Avatar of Howard Katz

ASKER

I have tried dozens of ways but still no success.   I need to find someone who has worked with the federal government E-Verify Web Service.  Here is the URL to it.  

https://stage.e-verify.uscis.gov/WebService/EmployerWebServiceV23.asmx

If you have successfully made a request and gotten a response, please help !!!

Thanks
Howard
ASKER CERTIFIED SOLUTION
Avatar of Howard Katz
Howard Katz
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I need more time to check this. Currently little bit busy.
I paid a Software Engineer ($249) help with using WCF to communicate with this Web Service after searching for 2 weeks unsucessfully
Stuff like this with no solution shouldn't be in the "must reads." Wasted my time. :(