I know how to add a WebReference in Visual Studio, easy enough.
I also know how to create a normal ASP.NET Web Service project, but that's not what I am doing here.
So, the WebService I have running looks like this:
try
{
if (host != null)
{
host.Close();
host = null;
}
baseAddress = new Uri("http://example.com:8080");
host = new WebServiceHost(typeof(MyProxy), baseAddress);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Opened += new EventHandler(host_Opened);
host.Closed += new EventHandler(host_Closed);
System.ServiceModel.Description.ServiceEndpoint se = host.AddServiceEndpoint(typeof(IMyProxy), new WebHttpBinding(), baseAddress);
se.Behaviors.Add(new System.ServiceModel.Description.WebHttpBehavior());
host.Open();
}
catch (Exception e)
{
}
// .... stuff ....
[ServiceContract]
public interface IMyProxy
{
[OperationContract]
[WebGet(UriTemplate = "GetArea?searchString={searchString}")]
GetAreaResult GetArea(string searchString);
}
// more stuff of course follows here
The problem is that when I try to add a WebReference to the above service in Visual Studio, I get an error.
"Add Service Reference" --> "Add Web Reference" and in the URL I write my URL, http://example.com:8080
Then I get "Service ... Endpoint not found." and the error message in the Add Web Reference box:
There was an error downloading 'http://example.com:8080/'. The request failed with HTTP status 404: Not Found. There was an error downloading 'http://example.com:8080/$metadata'. The request failed with HTTP status 404: Not Found.
If I open up a web browser and go directly to http://example.com:8080/GetArea the service is called/executed as expected.
So to rephrase the problem shorter: The WSDL/description isn't there, so I cannot add a Web Service reference.