Example calling an external webservice

M

Marc

I am trying to study ASP.NET by making some example programmes in Visual Web
Developper 2005 Express Edition.

I am trying to write a client that consumes a simple webservice like:

http://www.webservicex.net/uklocation.asmx?WSDL

I've added the webservice to my project, but how do I proceed? I have found
several examples but nothing clear what I really want. For example I have
found the below but that's with localhost. I do not have the webservice on
local host. Nor do I understand where localhost should be defined anyway.

protected void ConvertButton_Click(object sender, EventArgs e)
{
localhost.Convert wsConvert = new localhost.Convert();
double temperature =
System.Convert.ToDouble(TemperatureTextbox.Text);
FahrenheitLabel.Text = "Fahrenheit To Celsius = " +
wsConvert.FahrenheitToCelsius(temperature).ToString();
CelsiusLabel.Text = "Celsius To Fahrenheit = " +
wsConvert.CelsiusToFahrenheit(temperature).ToString();
}

Please give me some hints!

Marc Wentink
 
C

Cowboy \(Gregory A. Beamer\)

I think you are not looking for the Client. Here is an example I have not
tested, but it has the basic methodology wrapped in a class.

Service = http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl

Class =

using ServiceConsumptionLibrary.WeatherService;

namespace ServiceConsumptionLibrary
{
public class ServiceConsumer
{
public static WeatherService.ForecastReturn
GetForecastForUsPostalCode(string postalCode)
{
var client = new WeatherHttpGetClient();
var forecast = client.GetCityForecastByZIP(postalCode);

return forecast;
}
}
}

I have not tested through this yet (I would create a unit test, personally),
but the basic idea is sound and works like .NET 2.0+ works with all
services. And, yes, it is a bit more complex than 1.x.
 
M

Marc

"Cowboy (Gregory A. Beamer)" <[email protected]> schreef


Ok, now for something silly, and I am sorry this must be a real newbee question, and concurrently I am searching to solve this myself, but:

using ServiceConsumptionLibrary.WeatherService;
Gives

Error 1 The type or namespace name 'WeatherService' does not exist in the namespace 'ServiceConsumptionLibrary' (are you missing an assembly reference?) C:\Documents and Settings\Marc wentink\Mijn documenten\Visual Studio 2005\WebSites\H8Async\App_Code\ServiceConsumer.cs 10 33 C:\...\H8Async\

Now normally I would add a link to an assembly, a dll, with WeatherService in it, but what do I do now? I presume I do not have a dll with WeatherService in it.
 
J

Jeff Dillon

Add Web Reference in Solution Explorer

"Cowboy (Gregory A. Beamer)" <[email protected]> schreef


Ok, now for something silly, and I am sorry this must be a real newbee question, and concurrently I am searching to solve this myself, but:

using ServiceConsumptionLibrary.WeatherService;
Gives

Error 1 The type or namespace name 'WeatherService' does not exist in the namespace 'ServiceConsumptionLibrary' (are you missing an assembly reference?) C:\Documents and Settings\Marc wentink\Mijn documenten\Visual Studio 2005\WebSites\H8Async\App_Code\ServiceConsumer.cs 10 33 C:\...\H8Async\

Now normally I would add a link to an assembly, a dll, with WeatherService in it, but what do I do now? I presume I do not have a dll with WeatherService in it.
 
C

Cowboy \(Gregory A. Beamer\)

Here are the steps, based on the code I have:

First create a reference to the service
Name it WeatherService
Then add the code and run it

I will have to run that code and make sure it is fine. I will not have a chance until this weekend to set up a sample application, with a simple web service (and instructions). I will slap it up on my blog and post a note here when I am done. That way you will have an "instruction manual" in the blog entry.



"Cowboy (Gregory A. Beamer)" <[email protected]> schreef


Ok, now for something silly, and I am sorry this must be a real newbee question, and concurrently I am searching to solve this myself, but:

using ServiceConsumptionLibrary.WeatherService;
Gives

Error 1 The type or namespace name 'WeatherService' does not exist in the namespace 'ServiceConsumptionLibrary' (are you missing an assembly reference?) C:\Documents and Settings\Marc wentink\Mijn documenten\Visual Studio 2005\WebSites\H8Async\App_Code\ServiceConsumer.cs 10 33 C:\...\H8Async\

Now normally I would add a link to an assembly, a dll, with WeatherService in it, but what do I do now? I presume I do not have a dll with WeatherService in it.
 
M

Marc

"Cowboy (Gregory A. Beamer)" <[email protected]> schreef

"I will have to run that code and make sure it is fine. I will not have a
chance until this weekend to set up a sample application, with a simple web
service (and instructions). I will slap it up on my blog and post a note
here when I am done. That way you will have an "instruction manual" in the
blog entry."


Thanks! You're doing a whole lot!
 
M

Marc

Jeff Dillon said:
So what did you name it? You would refer to that name in your code

Ah.......so stupid me, I think....

As far as I can see I have not named them in any moment yet. But I think the
name would be: com.cdyne.ws. That one is automatically choosen for you. So I
must use that name, com.cdyne.ws, where in the examples localhost is used? I
just overlooked that EditBox. Well I am not really sure where and how to you
that name, but that is the connection then!?

FYI: this is what I did, step by step:

I have used the service cowboy pointed out to me.
I have selected Add Webreference in the Solution Explorer
Inserted the URL from Cowboy:

http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl

In the "Add Web Reference Window" that pops up.
Pressed "Go"
The three supported Webservices are shown.
At the right low there is an EditBox with the title "Web Reference Name".
That's filled with com.cdyne.ws by default. But you can change the name (I
see that now).
Then I pressed 'Add Reference'.

Now in the solution explorer an entry appears in App_WebReferences. A sort
of folder tree with:

com->cdyne->ws

And in the latter ws folder there are two files:

Weather.discomap
Weather.wsdl


Yours Sincerely grateful
Marc Wentink
 
M

Marc

"Marc" <[email protected]> schreef

And then calling the webservice is like this:

protected void Button1_Click(object sender, EventArgs e)
{
com.cdyne.ws.Weather wt = new com.cdyne.ws.Weather();
com.cdyne.ws.ForecastReturn FcR = wt.GetCityForecastByZIP("11202");
Label1.Text = FcR.ResponseText;
Label2.Text = "Tommorow Morning in NYC it's :
"+FcR.ForecastResult[1].Temperatures.MorningLow;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top