I'm trying to send an xml request to a url and the response will also be an xml response. I know how to call a service endpoint from an MVC application but I'm not sure how to call this url and how to read what it will give me back. This is what I have so far. Is this in the right direction?
Request:
<CityStateLookupRequest USERID=”xxxxxxxx”>
<ZipCode ID="0">
<Zip5>90210</Zip5>
</ZipCode>
</CityStateLookupRequest>
Response:
<CityStateLookupResponse>
<ZipCode ID="0">
<Zip5>90210</Zip5>
<City>BEVERLY HILLS</City>
<State>CA</State>
</ZipCode>
</CityStateLookupResponse>
C# Code:
var xmlRequest = new XElement("CityStateLookupRequest",
new XAttribute("USERID", "XXXXXXXXX"),
new XElement("ZipCode",
new XAttribute("ID", "0"),
new XElement("Zip5", "43065")));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" http://production.shippingapis.com/ShippingAPI.dll");
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(xmlRequest.ToString());
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
var xmlDoc = new XmlDocument();
xmlDoc.Load(response.GetResponseStream());
}