I have to consume a service REST
with C#
, but the truth is that I'm a bit lost on this issue.
on the one hand, the service to be consumed, requires several XML parameters that have the following format
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<prescription>
<patient>
<allergies>
<allergy>vidal://allergy/1</allergy>
<allergy>vidal://allergy/2</allergy>
<allergy>vidal://allergy/3</allergy>
</allergies>
<molecules>
<molecule>vidal://molecule/1</molecule>
</molecules>
<pathologies>
<pathology></pathology>
</pathologies>
<breastFeeding>NONE</breastFeeding>
<creatin>120</creatin>
<dateOfBirth>2012-11-08T15: 44:50.980+01:00</dateOfBirth>
<gender>MALE</gender>
<height>180.0</height>
<hepaticInsufficiency>SEVERE</hepaticInsufficiency>
<weeksOfAmenorrhea>5</weeksOfAmenorrhea>
<weight>80.0</weight>
</patient>
<prescription-lines>
<prescription-line>
<drugId>1</drugId>
<drugType>COMMON_NAME_GROUP</drugType>
</prescription-line>
<prescription-line>
<drugId>2</drugId>
<drugType>COMMON_NAME_GROUP</drugType>
</prescription-line>
</prescription-lines>
</prescription>
Where the necessary data, I get it from a form.
To make the call to the service, I have a function, where I specify the base address, which incorporates the necessary credentials to use the service, in addition to the method POST
for the query.
Resulting in this way
http://api-cl.vidal.fr/rest/api/alerts?app_id=5e151413&
app_key=f80c77cbd1ef392f541ee83889d1d2d4 method='post' result=" + xmlFile;
The input parameters described above, I transform them to xml
, through a function that adds the tags
necessary for each data.
This is the function I have to make a call.
public string EjecutarConsulta2(string url)
{
string strResponseValue = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = httpMethod.ToString();
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException("Codigo Error : " + response.StatusCode);
}
using (Stream responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
using (StreamReader reader = new StreamReader(responseStream))
{
strResponseValue = reader.ReadToEnd();
}
}
}
}
return strResponseValue;
}
My problem is that I do not know where the input parameters go in XML
format.
Do they have to be concatenated next to the URL? (I did this, but it did not work) .
Does anyone know how to execute these queries? Greetings