I'm currently in the process of learning .Net using C# and have begun experimenting with Web Services. With the help of someone on another thread: (Define which Endpoint to use when consuming a Web Service) I've managed to sort out my Endpoints and get some form of response form the Web Service I am using. My only problem now is that the response I receive seems to be an array and I need to be able to parse individual nodes from this array.
To shed some light on this, here is the XML structure that would be returned from calling the web service:
<ForecastReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ws.cdyne.com/WeatherWS/">
<Success>true</Success>
<ResponseText>City Found</ResponseText>
<State>DE</State>
<City>Newark</City>
<WeatherStationCity>Dover AFB</WeatherStationCity>
<ForecastResult>
<Forecast>
<Date>2014-04-22T00:00:00</Date>
<WeatherID>6</WeatherID>
<Desciption>Showers</Desciption>
<Temperatures>
<MorningLow>45</MorningLow>
<DaytimeHigh>71</DaytimeHigh>
</Temperatures>
<ProbabilityOfPrecipiation>
<Nighttime>00</Nighttime>
<Daytime>60</Daytime>
</ProbabilityOfPrecipiation>
</Forecast>
</ForecastResult>
</ForecastReturn>
I want to be able to access the nodes within this response by name or similar. So if I state I want the temperature, it will return the temperature however using result.Temperature doesn't seem to work in this case suggesting that the nodes do not become properties of the response object.
Here is my code so far:
Unhandled Exception: System.InvalidOperationException: An endpoint configuration section for contract 'Service1Reference.WeatherSoap'
could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.
My question is, how do I specify that my call to the web service should use one of the SOAP endpoints? My code so far can be found below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication1.Service1Reference;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter ZipCode: ");
var line = Console.ReadLine();
if (line == null)
{
return;
}
WeatherSoapClient svc = null;
bool success = false;
try
{
svc = new WeatherSoapClient();
var request = line;
var result = svc.GetCityForecastByZIP(request);
Console.WriteLine("The result is:");
Console.WriteLine(result);
Console.Write("ENTER to continue:");
Console.ReadLine();
svc.Close();
success = true;
}
finally
{
if (!success && svc != null)
{
svc.Abort();
}
}
}
}
}
How can I adapt this to access the different nodes in my response from this web service?
Any help would be greatly appreciated.