使用 WCF 服务参考:未找到终结点/未找到 404 页面
Consuming WCF Service Reference: Endpoint not found / 404 page not found
你好,我知道这个话题可能看起来和类似的话题很熟悉,但我可以告诉你,我是在搜索了一整天的相关问题后才来寻求帮助的,因为none 的建议解决方案对我有用。
我创建了一个 WCF REST 服务应用程序,其中只有一个在我的计算机上本地运行的服务以及一个 ASP.NET WebForm 客户端 消耗它(在 Windows 7 上的 VS 2013 的单个实例上)。
服务的所有操作都运行良好。
- GET操作可以在浏览器中测试成功
- POST 使用 Postman 浏览器扩展可以成功测试操作。
问题:当我尝试使用客户端上的服务引用访问此服务时,例如:
AuthorRESTServiceClient service = new AuthorRESTServiceClient("AuthorServiceBinding");
string value = service.Test(); //GET operation that should return a "Hello World"
客户端然后抛出 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.
并包含一个内部 WebException
:
The remote server returned an error: (404) Not Found
这是 WCF 服务应用程序 服务器的 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" />
这是 ASP.NET Webform 客户端的 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>
我做错了什么?任何帮助将不胜感激。
您没有指定服务端点地址,您将其留空。将服务配置文件 endpoint
元素中的 address
属性设置为您在客户端配置中设置的相同值。此外,根据您托管 WCF 服务的方式,您可能需要设置服务基址。
我认为可能存在三个问题:
- 在 WCF 应用程序的 Web.Config 中,您有
<add binding="basicHttpsBinding" scheme="https" />
,但客户端中的 URL 使用 "http"。
- 服务器总是 运行 在端口 49414 上吗?
- 您网站的身份验证设置是否正确?查看 EndpointNotFoundException: There was no endpoint listening at。
尝试在客户端项目上添加您的 REST 服务的 Web 引用,它会自动对您的客户端进行一些更改 web.config 并且只是从您的 WCF web.config 文件中删除协议映射部分。这可能对你有帮助。
你好,我知道这个话题可能看起来和类似的话题很熟悉,但我可以告诉你,我是在搜索了一整天的相关问题后才来寻求帮助的,因为none 的建议解决方案对我有用。
我创建了一个 WCF REST 服务应用程序,其中只有一个在我的计算机上本地运行的服务以及一个 ASP.NET WebForm 客户端 消耗它(在 Windows 7 上的 VS 2013 的单个实例上)。
服务的所有操作都运行良好。
- GET操作可以在浏览器中测试成功
- POST 使用 Postman 浏览器扩展可以成功测试操作。
问题:当我尝试使用客户端上的服务引用访问此服务时,例如:
AuthorRESTServiceClient service = new AuthorRESTServiceClient("AuthorServiceBinding");
string value = service.Test(); //GET operation that should return a "Hello World"
客户端然后抛出 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.
并包含一个内部 WebException
:
The remote server returned an error: (404) Not Found
这是 WCF 服务应用程序 服务器的 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" />
这是 ASP.NET Webform 客户端的 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>
我做错了什么?任何帮助将不胜感激。
您没有指定服务端点地址,您将其留空。将服务配置文件 endpoint
元素中的 address
属性设置为您在客户端配置中设置的相同值。此外,根据您托管 WCF 服务的方式,您可能需要设置服务基址。
我认为可能存在三个问题:
- 在 WCF 应用程序的 Web.Config 中,您有
<add binding="basicHttpsBinding" scheme="https" />
,但客户端中的 URL 使用 "http"。 - 服务器总是 运行 在端口 49414 上吗?
- 您网站的身份验证设置是否正确?查看 EndpointNotFoundException: There was no endpoint listening at。
尝试在客户端项目上添加您的 REST 服务的 Web 引用,它会自动对您的客户端进行一些更改 web.config 并且只是从您的 WCF web.config 文件中删除协议映射部分。这可能对你有帮助。