C# – Consume web service from Class Library

cvisual studio 2010wcfweb services

I have successfully created an ASP.net website to make calls to a Soap Web service.

Now I need to turn it into a Class Library that I can call via Com from Classic ASP.

This post on Consume web service in asp.net app from a class library says that I need to add the web service as use "Add Service Reference" instead of "Add Web Reference" to add a reference to the Webservice.

When I try to do that I get an error:

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.

…but when I click on advanced and then add then "Add Web Reference" I can add it fine.

Questions:

1) Is it necessary to use "Add Service Reference" instead of "Add Web Reference"?
2) Why, what's the difference?
3) What are potential causes of this error, and how can I figure this out, for instance I don't know why it's going to port 8080 to look for the WSDL http://theURL.com:8008/asmx/reguspublic.asmx?wsdl when it should go to http://theURL.com/asmx/reguspublic.asmx?wsdl

Best Answer

Service Reference is for Windows Communication Foundation (WCF) services and WCF Data Services where as Web Reference is used when using 'legacy' or asmx web services.

So for 'asmx' you should use web reference and not service reference.

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

Regarding the error:
WCF services expose Metadata that enables them to interact with different kinds of endpoints and data. .NET 2.0 asmx webservices only have one endpoint @SOAP. So 'asmx' web services does not expose any metadata due to which the error occurs.

Related Topic