2011-06-13 80 views
3

我已经成功创建了一个ASP.net网站来调用Soap Web服务。从类库中消费Web服务

现在我需要把它变成一个类库,我可以通过COM从经典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)是否有必要使用“添加服务引用”,而不是“添加Web引用”?
2)为什么有什么区别?
3)什么是这个错误的潜在原因,我怎么可以算出来,比如我不知道为什么它会8080端口查找WSDL http://theURL.com:8008/asmx/reguspublic.asmx?wsdl时候就应该去http://theURL.com/asmx/reguspublic.asmx?wsdl

+0

请参阅如何格式化消息。格式化指南位于编辑的右侧。例如,你需要在行尾加两个空格来换行。 – 2011-06-13 11:52:10

回答

5

服务参考用于Windows Communication Foundation(WCF)服务和WCF数据服务,其中使用“Web引用”时使用“传统”或asmx Web服务。

所以对于'asmx'你应该使用web引用而不是服务引用。

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

关于错误:
WCF服务暴露元数据,使他们能够与不同类型的端点和数据的交互。 .NET 2.0 asmx webservices只有一个端点@SOAP。因此,'asmx'web服务不会公开任何由于发生错误而导致的元数据。

+0

如何判断Web服务是WCF服务还是传统服务? – iKode 2011-06-14 08:08:30

+0

asmx | .net 2.0或之前=旧版,svc = wcf。 – 2011-06-14 08:24:21

1

不需要它,你需要将web服务配置复制到目标可执行文件的应用配置中,因为当你从库中调用web服务时,web服务会从.exe.config中查找配置文件存在

您可以设置Web服务URL编程就像我做了什么

AC.CCRS.WebService.MyWebServices c = new AC.CCRS.WebService.MyWebServices(); 
      c.Url =... "the webservice host url