Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Endpoint not found When Hosting in ASP.NET

Tags:

asp.net

wcf

I get "Endpoint not found" when attempting to access my service via the browser at

http://localhost:10093/Services/Service1.svc

I get "Error: Cannot obtain Metadata from http://localhost:10093/Services/Service1.svc" when attempting to access the same address from the wcftestclient.

If I place a breakpoint in the service implementation it is hit, so I assume the svc file is setup correctly:

<%@ ServiceHost Language="C#" Debug="true" 
Service="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service" 
Factory="CommonServiceFactory.WebServiceHostFactory,CommonServiceFactory" %>

Here is my config:

<system.serviceModel>
    <services>
      <service name="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service"
               behaviorConfiguration="MainServiceBehavior">
        <endpoint name="newEndpoing" 
             binding="basicHttpBinding" bindingConfiguration=""
             contract="MyApp.Core.Service.IMyAppService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MainServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
like image 389
chief7 Avatar asked Oct 02 '10 20:10

chief7


3 Answers

So you have a *.svc file to host your service. Can you right-click in Visual Studio on that file and say "Show in Browser" ? Do you get anything there, or does it throw an error right away??

Next: your service endpoint has no address="" attribute, which I believe is mandatory - try adding that (even if you don't specify an address in it).

If you're hosting in IIS, your service address is defined by the virtual directory where your SVC file is present, and the SVC file itself - you might not be able to define a specific port or anything (IIS will handle that).

So try to connect to

http://localhost/Services/Service1.svc

Does that work by any chance??

Update: reading your post again more closely, you're specifying a special factory for the service - WebServiceHostFactory. Is this the default WebServiceHostFactory provided by .NET, or is that something you built yourself??

The point is: the .NET WebServiceHostFactory will use the webHttpBinding for RESTful WCF services - that won't work with an endpoint specifying basicHttpBinding, nor will the REST service have any metadata....

Update #2: try to use just the service's fully qualified class name, but without the assembly specification, in both your SVC file, and the config file.

So change this:

Service="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service" 

to this:

Service="MyApp.Core.Service.Service.MyAppService" 

SVC file:

<%@ ServiceHost Language="C#" Debug="true" 
Service="MyApp.Core.Service.Service.MyAppService" %>

Config file:

<services>
  <service name="MyApp.Core.Service.Service.MyAppService"
           behaviorConfiguration="MainServiceBehavior">
     <endpoint name="newEndpoing" 
          binding="basicHttpBinding" bindingConfiguration=""
          contract="MyApp.Core.Service.IMyAppService" />
  </service>
</services>
like image 106
marc_s Avatar answered Nov 05 '22 12:11

marc_s


On your Solution Explorer, open your .svc by using "view markup", make sure you have something like:

... ServiceHost Language="C#" Debug="true" 
    Service="Yourservice.yourservice" CodeBehind="yourservice.svc.cs" %>

Where Yourservice is your namespace and yourservice is name of your .svc created.

like image 31
luna lee Avatar answered Nov 05 '22 12:11

luna lee


I had the same results (Endpoint not found) when I put this in the browser window

http://c143253-w7a:2221/ws/myService.svc

Then when I put the whole url to the method, it ran fine. Like this

http://c143253-w7a:2221/ws/myService.svc/HelloWorld?theInput=pds

In my .svc file I am using this

Factory="System.ServiceModel.Activation.WebServiceHostFactory"

I think that the Factory doesn't spin up the endpoint until it is needed. That is why we get Endpoint not found in the browser(?).

Here is what the method signature looks like in the interface code.

using System.ServiceModel.Web;

[WebGet(UriTemplate = "HelloWorld?theInput={theInput}")]
[OperationContract]
string HelloWorld(string theInput);

I put nothing in the webconfig. There is some stuff in there, but I think that came in w the VS, Add WCF Service template. It looks like this:

<system.serviceModel>
 <behaviors>
   <serviceBehaviors>
     <behavior name="">
       <serviceMetadata httpGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="false" />
     </behavior>
   </serviceBehaviors>
 </behaviors>
 <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
like image 45
pdschuller Avatar answered Nov 05 '22 10:11

pdschuller