StingyJack
StingyJack

Reputation: 19479

Calling a WCF service from client app receives EndpointNotFoundException, but does not error on browser

I have a newly created WCF .SVC that is hosted in an ASP.NET website that also hosts traditional ASMX-style services.

If I call the single method that is contained in the SVC, I get the following message.

"There was no endpoint listening at http://localhost/REDACTEDSITE/LicenseVerification.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."

However, I can paste that link into any browser on my local machine and get the "This is a Windows© Communication Foundation service. Metadata publishing for this service is currently disabled." page.

The IIS logs show that the browsers are issuing GET requests and receiving a 200 response. The WCF clients are issuing POST requests and receiving 404.0 responses.

These are the latest config settings I have used. They are somewhat minimal.

host

<system.serviceModel>
   <client entries for other services that work>

    <services>
      <service name="LicenseVerification.svc">
        <endpoint address="LicenseVerification.svc"
            binding="basicHttpBinding" bindingConfiguration="" contract="Management.ILicenseVerification" />
      </service>
    </services>

  </system.serviceModel>

client

<system.serviceModel>
    <client>
      <endpoint address="http://localhost/REDACTEDSITE/LicenseVerification.svc"
          binding="basicHttpBinding" bindingConfiguration="" contract="Management.ILicenseVerification"
          name="LicenseVerificationClient">
      </endpoint>
    </client>
  </system.serviceModel>

contract

 [ServiceContract]
    public interface ILicenseVerification
    {
        [WebInvoke(Method="GET")] //have tried WebGet()
        [OperationContract]
        LicenseInfo GetProfileLicenseInfo(string profileName);
    }

service impl

  public class LicenseVerification : ILicenseVerification
    {
        LicenseInfo ILicenseVerification.GetProfileLicenseInfo(string profileName)
        {
            ProfileInfo _pi = ProfileHelper.GetRequestedProfileInfo(profileName);
            if (_pi == null)
            {
                return null;
            }

            return LicenseVerifier.GetLicenseInfo(_pi);
        }
    }

I have tried re-registering asp.net 4.0, repairing the service model, restarting IIS, trashing and recreating the config files using the MS service config utility and by hand and I still cannot get this to work.

These are small requests (a few KB), so I don't think its a size problem.

The only thing that sticks out is the GET/POST, but that hasn't been a problem before for SVC's that I have made.

My local environment is Win7/64, VS2010, .NET 4.

Please let me know what else to try. I have culled the various SO posts on the same and had no luck (even the ones that look blatantly different).

Upvotes: 0

Views: 1527

Answers (2)

StingyJack
StingyJack

Reputation: 19479

After following carlosfigueira's advice and dropping the [web*] attributes and fixing the name of the service in the config, I was able to get a proper service help page but this was still not working from clients.

However, I was now able to use the svcutil to generate the code and config that my service required. What I found from that generated output.config file was that the endpoint address was duplicated at the end, like this...

http://localhost/REDACTEDSITE/LicenseVerification.svc/LicenseVerification.svc

This is the endpoint that the client needed to hit in order to consume the service, and when I updated the clients config to hit that endpoint, it WORKED!

This was still not optimal, so I tried removing the address element from my service config so that it now looks like this (sans behavior confg).

  <service name="Management.LicenseVerification">
    <endpoint binding="basicHttpBinding" contract="Management.ILicenseVerification" />
  </service>

And it still works!

I am somewhat confused as to why this would append the address element, other than maybe its a side effect of hosting this in asp.net. Perhaps address elements (and base address) do not need to be configured in this case?

In any event, this is now working.

Upvotes: 0

carlosfigueira
carlosfigueira

Reputation: 87293

The value of the "name" property of the <service> element in the server's config is incorrect. It should list the fully-qualified name of the service class (probably Management.LicenseVerification), and not the name of the .svc file.

A few more issues:

  • You're using [WebInvoke(Method = "GET")] in your operation. Use [WebGet] instead if you want it to be accessed via GET
  • [WebInvoke] (and [WebGet]) are only honored for endpoints which use the webHttpBinding and have an endpoint behavior with <webHttp/>, none of those you have (you're using basicHttpBinding).
  • The browser is sending a GET request, but it's not invoking the operation, it's probably getting the service help page. So it's probably not really "working" from the browser.

Upvotes: 1

Related Questions