How to call a webservice that wasn't developed in .NET

In the past, I have had experience calling WCF services or ASMX services, you just add service reference to the .svc or .asmx url and it generates the proxy for you, and then you have intellisense for calling the methods.

Is it the same for a non .net webservice?

I need to call this http://www.earthtools.org/webservices.htm

from c# code in a winrt app, but I just dont know how

Answers


If you have WSDL then you can add reference to that service. but here you try to call REST service.

you need to send post request and rad the response as:

private const string BASE_URL = "http://www.earthtools.org/timezone";
private const string REQUEST_URL_FORMAT = "{0}/{1}/{2}";

public timezone GetTimeZone(double latitude, double longitude)
{
    var uriString = String.Format(REQUEST_URL_FORMAT, BASE_URL, latitude, longitude);
    var requestUri = new Uri(uriString);

    var request = WebRequest.Create(requestUri);
    using (var response = request.GetResponse())
    {
        using (var responseStream = response.GetResponseStream())
        {
            var ser = new XmlSerializer(typeof (timezone));
            var result = (timezone) ser.Deserialize(responseStream);
            return result;
        }
    }
}

example from here.


If they were SOAP web services, then you could still point Visual Studio to the .WSDL endpoint and have it generate the client proxy. But these appear to be REST services. I think your best bet is to use XDocument.Load or somesuch, and then use Linq-to-XML or XML deserialization to convert the XML into C# classes.

For example, let's say you want to call this service. An easy way to get lat/lng result would be something like this:

XDocument xdoc = XDocument.Load("http://www.earthtools.org/height/52.4822/-1.8946");
var lat = (decimal)xdoc.Element("location").Element("latitude");
var lng = (decimal)xdoc.Element("location").Element("longitude");

Microsoft Marketing guy's will tell that web services are interoperable, even with heterogeneous system.

It's half the truth. Web services standard is actually multiplatform. On the field, however, it can be a bit more complicated. Different philosophy of different systems can lead to different behaviors.

Not long ago, I add to query a Web service built with Java Web logic (not sure of the system, I was on the client side) with Visual Studio 2010. It was a bit of pain because :

  1. Visual Studio proxy wizard only understand inline schema. Here the schema was references within the wsdl using <xsd:import>. Visual Studio does not understand that
  2. Then I moved to svcutil to generate from command line the proxies. This was not working directly, because of some errors in the WSDL file (this file was manually build by the service provider). I have to ask to the service provider to clean it's wsdl file
  3. the xsd file representing the DTOs were shared by several web services. This lead to duplicate the same classes in each proxies, even if not used by all services. I had to tweak with partial classes to "rewrap" into unique classes.

To conclude, you can the limit of the term "Interoperability". The standards say it's interoperable, but the field says not always.

I welcome the newcoming world of "rest" services. This can simplify a lot the interoperability. The drawback is that you may have to build yourself a part of the plumbing.

Good news, the service you mentioned seems to embrace this rest philosophy. It won't be straightforward, but you can build simple Http request (post, get or put) to query this service.


Need Your Help

What is the way to add translation to an array?

ruby-on-rails ruby-on-rails-3.1 internationalization activesupport

Sorry if this is really easy. But I have tried many ways to add I18n and does not seem to work.

How to test COM object integrity automatically?

c++ testing visual-c++ com interface

Every COM object must have integrity. In simplified terms this means that if an object implements 3 interfaces - A, B and C and I have A* pointer to the object I must be able to successfully