Consuming WCF Service Reference: Endpoint not found / 404 page not found

岁酱吖の 提交于 2019-12-11 10:36:45

问题


Hi, I know this topic might look familiar to similar topic but I can tell you that it is after an entire day of searching on related issues that I come for help, because none of the suggested solutions has worked for me.

I have created a WCF REST Service Application with only one service that runs locally on my computer as well as a ASP.NET WebForm Client that consumes it (both on individual instance of VS 2013 on a Windows 7).

All the operations of the service work perfeclty fine.

  • GET operations can be successfully tested in the browser
  • POST operations can be successfully tested using Postman browser extension.

Problem: When I try to access this service using a Service Reference on the client such as:

AuthorRESTServiceClient service = new AuthorRESTServiceClient("AuthorServiceBinding");
string value = service.Test(); //GET operation that should return a "Hello World"

the client then throws an EndpointNotFoundException:

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

And contains an inner WebException:

The remote server returned an error: (404) Not Found

Here is the partial code of the WCF Service Application server's Web.config:

  <system.serviceModel>
    <services>
      <service name="WCFAuthorEntryService.AuthorRESTService">
        <endpoint address=""
                  binding="webHttpBinding"
                  contract="WCFAuthorEntryService.IAuthorRESTService"
                  behaviorConfiguration="web">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

And here's the partial code of the ASP.NET Webform client's Web.config

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="AuthorServiceBinding"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:49414/AuthorRESTService.svc"
                binding="basicHttpBinding"
                bindingConfiguration="AuthorServiceBinding"
                contract="AuthorServiceReference.IAuthorRESTService"
                name="AuthorServiceBinding"/>
    </client>
  </system.serviceModel>

What am I doing wrong? Any help would be much appreciated.


回答1:


There are three things that stand out to me as possible problems:

  1. In the Web.Config for the WCF application you have<add binding="basicHttpsBinding" scheme="https" /> but the URL in the the client uses "http".
  2. Is the server always running on port 49414?
  3. Are your site's authentication settings correct? Check out EndpointNotFoundException: There was no endpoint listening at.



回答2:


You didn't specify the service endpoint address, you left it blank. Set the address attribute in the endpoint element on the services config file to the same value you set in the clients config. Also, depending how you host your WCF service, you might want to set the service base address.




回答3:


Try to add Web Reference of your REST service on client project, it will automatically make some changes to your client web.config and just remove protocol mapping section from your WCF web.config file. This may help you.



来源:https://stackoverflow.com/questions/29505467/consuming-wcf-service-reference-endpoint-not-found-404-page-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!