Last post Mar 10, 2017 09:13 AM by PatriceSc
Jul 22, 2013 05:00 AM|DaltonGR|LINK
I have a third party wcf service, below is their API url for the service
WSDL Location - https://api.cars.com/en/soap/index?wsdl
Server End Point - https://api.cars.com/en/soap/index
and i am trying to consume a method from their service, getVehicles. It gets an xml response from me, the client and returns an xml back.
below is the code i use to get the data, but can seem to find how to invoke the service.
string oRequest = @"My XML data to be sent.";
//Builds the connection to the WebService.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://api.cars.com/en/soap/index?wsdl");
req.ContentType = "text/xml; charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
//Passes the SoapRequest String to the WebService
using (Stream stm = req.GetRequestStream())
using (StreamWriter stmw = new StreamWriter(stm))
//Gets the response
WebResponse response = req.GetResponse();
//Writes the Response
Stream responseStream = response.GetResponseStream();
StreamReader sr = new StreamReader(responseStream);
string s = sr.ReadToEnd();
XmlDocument doc = new XmlDocument();
catch (Exception e)
if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError)
WebResponse errResp = ((WebException)e).Response;
using (Stream respStream = errResp.GetResponseStream())
i get an internal error (500) from web server, and if i remove the /getVehicles from SOAPAction i get a xml of the service metadata i think. Any ideas what i am doing wrong?? Thanks for the help in advance...
One more thing the URI's are fictional but are following the real structure...
Mar 10, 2017 09:13 AM|PatriceSc|LINK
Old but the principle is
That in Visual Studio you'll use this tool to point to the
https://api.cars.com/en/soap/index?wsdl document. This is a description of the service that will be used to build client side proxy classes.
Then you'll just use those classes that will deal with handling sending data back and forth using XML without having ever to deal with that yourself...