c# - 从类库中使用 Web 服务

标签 c# wcf web-services visual-studio-2010

我已成功创建一个 ASP.net 网站来调用 Soap Web 服务。

现在我需要将它变成一个类库,我可以通过 Com 从 Classic ASP 调用它。

这篇文章在 Consume web service in asp.net app from a class library说我需要添加 Web 服务,因为使用“添加服务引用”而不是“添加 Web 引用”来添加对 Web 服务的引用。

当我尝试这样做时出现错误:

Metadata contains a reference that cannot be resolved: 'http://theURL.com:8008/asmx/publicServiceAddress.asmx?wsdl'.
There was an error downloading 'http://theURL.com:8008/asmx/publicServiceAddress.asmx?wsdl'.
Unable to connect to the remote server A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 77.95.80.35:8008 Metadata contains a reference that cannot be resolved: 'http://theURL.com/asmx/publicServiceAddress.asmx'. Metadata contains a reference that cannot be resolved: 'http://theURL.com/asmx/publicServiceAddress.asmx'.
If the service is defined in the current solution, try building the solution and adding the service reference again.

...但是当我单击高级然后添加“添加 Web 引用”时,我可以很好地添加它。

问题:

1)是否有必要使用“Add Service Reference”而不是“Add Web Reference”?
2) 为什么,有什么区别?
3) 这个错误的潜在原因是什么,我怎么能弄清楚,例如我不知道为什么要到端口 8080 寻找 WSDL http://theURL.com:8008/asmx/reguspublic.asmx?wsdl什么时候应该转到http://theURL.com/asmx/reguspublic.asmx?wsdl

最佳答案

服务引用适用于 Windows Communication Foundation (WCF) 服务和 WCF 数据服务,其中在使用“旧版”或 asmx 网络服务时使用 Web 引用。

因此对于“asmx”,您应该使用网络引用而不是服务引用。

http://alexduggleby.com/2008/08/24/add-web-reference-instead-of-service-reference-in-visual-studio-2008/

关于错误:
WCF 服务公开元数据,使它们能够与不同类型的端点和数据进行交互。 .NET 2.0 asmx web 服务只有一个端点@SOAP。因此,“asmx”Web 服务不会公开导致错误发生的任何元数据。

关于c# - 从类库中使用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6330014/

相关文章:

c# - 通用类 (.CS) 中的应用程序路径

c# - 是否可以在低于 6 的 EF 版本中拦截来自 EF 的 DB 查询?

iphone - 实现 Web 服务还是使用脚本进行 iPhone 应用程序交互?

java - Json Web服务数据检索

web-services - Content-Type 协商在 REST 应用程序中是典型的还是非典型的?

c# - 关于c#中|=的问题

c# - 安全删除目录

wcf - 在 WCF 中使用 Schema 进行消息验证

c# - 错误 : The type or namespace name 'ApplicationUser' could not be found in Visual Studio 2013

wcf - WCF 4.0:WebMessageFormat.Json无法使用WCF REST模板