调用外部Web服务的示例 [英] Example calling an external webservice
问题描述
我正在尝试通过在Visual Web中制作一些示例程序来学习ASP.NET
Developper 2005 Express Edition。
我正在尝试写一个客户端使用如下简单的Web服务:
http: //www.webservicex.net/uklocation.asmx?WSDL
我已将web服务添加到我的项目中,但如何继续?我已经找到了几个例子,但没有什么清楚我真正想要的东西。比如我在下面找到了
,但这与localhost有关。我在
本地主机上没有网络服务。我也不明白应该在哪里定义localhost。
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(温度).ToStrin g();
CelsiusLabel.Text =" Celsius To Fahrenheit =" +
wsConvert.CelsiusToFahrenheit(温度).ToStrin g();
}
请给我一些提示!
Marc Wentink
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).ToStrin g();
CelsiusLabel.Text = "Celsius To Fahrenheit = " +
wsConvert.CelsiusToFahrenheit(temperature).ToStrin g();
}
Please give me some hints!
Marc Wentink
推荐答案
试试这个演练:
http://msdn.microsoft.com/en-us/ libr ... 54(VS.71).aspx
您必须设置服务才能执行此操作。一旦你理解了这一点,你就可以创建其他服务或连接到你想要消费的服务。我可以
告诉你你所指出的服务,但它非常慢。
-
Gregory A Beamer
MVP,MCP:+ I,SE,SD,DBA
订阅我的博客
http://feeds.feedburner.com/GregoryBeamer#
或只需阅读:
http://feeds.feedburner.com/GregoryBeamer
************************************* *******
|创造性思考! |
***************************************** ***
" Marc" < no ***** @ chello.nlwrote in message
news:ef **************** @ TK2MSFTNGP05.phx.gbl ...
Try this walkthrough:
http://msdn.microsoft.com/en-us/libr...54(VS.71).aspx
You will have to set up the service to do it. Once you understand that, you
can create other services or connect to the one you want to consume. I could
show you with the service you have pointed out, but it is extremely slow.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"Marc" <no*****@chello.nlwrote in message
news:ef****************@TK2MSFTNGP05.phx.gbl...
>我试图通过在Visual Develop / Web Developper 2005 Express Edition中制作一些示例程序来学习ASP.NET。
>
我正在尝试编写一个消费简单Web服务的客户端,例如:
http://www.webservicex.net/uklocation.asmx?WSDL
我已将webservice添加到我的项目中,但我该怎么办?我有几个例子,但是没有清楚我真正想要的东西。例如我
已经找到了下面的内容,但这与localhost有关。我在本地主机上没有
webservice。我也不明白localhost应该在哪里定义
.
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(温度).ToStrin g();
CelsiusLabel.Text =" Celsius To Fahrenheit =" +
wsConvert.CelsiusToFahrenheit(温度).ToStrin g();
}
请给我一些提示!
Marc Wentink
>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).ToStrin g();
CelsiusLabel.Text = "Celsius To Fahrenheit = " +
wsConvert.CelsiusToFahrenheit(temperature).ToStrin g();
}
Please give me some hints!
Marc Wentink
我认为您不是在寻找客户。这是一个我没有测试过b $ b b的例子,但它有一个基本的方法包装在一个类中。
服务= http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl
Class =
使用ServiceConsumptionLibrary.WeatherService;
命名空间ServiceConsumptionLibrary
{
公共类ServiceConsumer
{
public static WeatherService.ForecastReturn
GetForecastForUsPostalCode(string postalCode)
{
var client = new WeatherHttpGetClient();
var forecast = client.GetCityForecastByZIP(postalCode);
返回预测;
}
}
}
我还没有通过这个测试然而(我会亲自创建一个单元测试),
但基本的想法是健全的,像.NET 2.0+一样适用于所有
服务。而且,是的,它比1.x更复杂。
-
Gregory A. Beamer
MVP ,MCP:+ I,SE,SD,DBA
订阅我的博客
http://feeds.feedburner.com/GregoryBeamer#
或者只是阅读它:
http://feeds.feedburner.com/GregoryBeamer
********************************************
|创造性思考! |
***************************************** ***
" Cowboy(Gregory A. Beamer)" < No ************ @ comcast.netNoSpamMwrote
消息新闻:u6 ************** @ TK2MSFTNGP04.phx .gbl ...
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.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:u6**************@TK2MSFTNGP04.phx.gbl...
尝试本演练:
http://msdn.microsoft.com/en-us/libr...54(VS.71).aspx
您必须设置服务才能执行此操作。一旦你理解了这一点,你就可以创建其他服务或连接到你想要消费的服务。我用b $ b可以告诉你你所指出的服务,但是它非常好。
慢。
-
Gregory A. Beamer
MVP,MCP:+ I,SE,SD,DBA
订阅我的博客
http://feeds.feedburner.com/GregoryBeamer#
或只是阅读它:
http:// feeds。 feedburner.com/GregoryBeamer
***************************** ***************
|创造性思考! |
***************************************** ***
" Marc" < no ***** @ chello.nlwrote in message
news:ef **************** @ TK2MSFTNGP05.phx.gbl ...
Try this walkthrough:
http://msdn.microsoft.com/en-us/libr...54(VS.71).aspx
You will have to set up the service to do it. Once you understand that,
you can create other services or connect to the one you want to consume. I
could show you with the service you have pointed out, but it is extremely
slow.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"Marc" <no*****@chello.nlwrote in message
news:ef****************@TK2MSFTNGP05.phx.gbl...
>>我试图通过在Visual Develop / Web Developper 2005 Express Edition中制作一些示例程序来学习ASP.NET。
<我正在尝试编写一个使用简单Web服务的客户端,例如:
http://www.webservicex.net/uklocation.asmx?WSDL
我已将webservice添加到我的项目中,但如何继续?我已经找到了几个例子,但没有说清楚我真正想要的是什么。例如
我找到了下面的内容,但这与localhost有关。我在本地主机上没有
web服务。我也不了解localhost应该在哪里定义。
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(温度).ToStrin g();
CelsiusLabel.Text =" Celsius To Fahrenheit =" +
wsConvert.CelsiusToFahrenheit(温度).ToStrin g();
}
请给我一些提示!
Marc Wentink
>>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).ToStrin g();
CelsiusLabel.Text = "Celsius To Fahrenheit = " +
wsConvert.CelsiusToFahrenheit(temperature).ToStrin g();
}
Please give me some hints!
Marc Wentink
" Cowboy(Gregory A. Beamer)" < No ************ @ comcast.netNoSpamMschreef
好的,现在为了傻事,我很抱歉这一定是一个真正的新问题,同时我也是寻求解决这个问题,但是:
使用ServiceConsumptionLibrary.WeatherService;
给予
错误1类型或命名空间名称''WeatherService''在命名空间''ServiceConsumptionLibrary'中不存在(你是否缺少程序集引用?)C:\ Document and Settings \Marc wentink \Mijn documenten \ Visual Studio 2005 \ WebSites\H8Async\App_Code\ServiceConsumer.cs 10 33 C:\ ... \ H8Async \
现在通常我会添加一个指向程序集的链接, dll,里面有WeatherService,但我现在该怎么办?我认为我没有带有WeatherService的dll。
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMschreef
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.
这篇关于调用外部Web服务的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!