WCF AJAX 启用的服务创建正常,但方法 returns 404
WCF AJAX enabled service created OK, but method returns 404
这是我的第一个WCF服务,所以请理解。 :)
- 我有一个现有的 ASP.Net 网站,到目前为止 运行 没问题。
- 我使用 VS 2017 添加了一个新的 WCF Ajax 启用服务。
- VS 创建了 .svc 和 .cs 文件,它还对 web.config.
进行了更改
- 我确保在服务器角色中启用了 HTTP 激活。
当通过浏览器导航到服务 url 时,服务页面加载。好的。
当我尝试添加“/DoWork”以访问作为默认创建的方法时,出现 404 错误。
我一直在疯狂尝试不同的教程建议。没有工作。
我一定错过了一些简单的东西。服务器级别可能未启用某些功能?
我认为 VS 添加的 WCF 代码可以正常工作,对吗?
为什么是 404?????
我错过了什么????
感谢您的帮助和最诚挚的问候,
乌达尔
这里是web.config
的相关部分
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="NativeAppConnectorWCFAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="NativeAppConnectorWCF">
<endpoint address="" behaviorConfiguration="NativeAppConnectorWCFAspNetAjaxBehavior"
binding="webHttpBinding" contract="NativeAppConnectorWCF" />
</service>
</services>
</system.serviceModel>
如果使用 webhttpbinding,则需要将 webHttp 添加到端点行为中:
<endpointBehaviors>
<behavior name="ESEndPointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
这是我的配置文件,我启用了帮助文档:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.serviceModel>
<services>
<service name="Demo_rest_ConsoleApp.Service1" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8763/TEST/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="webHttpBinding"
contract="Demo_rest_ConsoleApp.IService1" behaviorConfiguration="ESEndPointBehavior"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="ESEndPointBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceThrottling maxConcurrentCalls="1" maxConcurrentInstances="1" maxConcurrentSessions="1"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
如果问题仍然存在,请随时告诉我。
这是我的第一个WCF服务,所以请理解。 :)
- 我有一个现有的 ASP.Net 网站,到目前为止 运行 没问题。
- 我使用 VS 2017 添加了一个新的 WCF Ajax 启用服务。
- VS 创建了 .svc 和 .cs 文件,它还对 web.config. 进行了更改
- 我确保在服务器角色中启用了 HTTP 激活。
当通过浏览器导航到服务 url 时,服务页面加载。好的。 当我尝试添加“/DoWork”以访问作为默认创建的方法时,出现 404 错误。
我一直在疯狂尝试不同的教程建议。没有工作。 我一定错过了一些简单的东西。服务器级别可能未启用某些功能? 我认为 VS 添加的 WCF 代码可以正常工作,对吗?
为什么是 404????? 我错过了什么????
感谢您的帮助和最诚挚的问候,
乌达尔
这里是web.config
的相关部分 <system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="NativeAppConnectorWCFAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="NativeAppConnectorWCF">
<endpoint address="" behaviorConfiguration="NativeAppConnectorWCFAspNetAjaxBehavior"
binding="webHttpBinding" contract="NativeAppConnectorWCF" />
</service>
</services>
</system.serviceModel>
如果使用 webhttpbinding,则需要将 webHttp 添加到端点行为中:
<endpointBehaviors>
<behavior name="ESEndPointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
这是我的配置文件,我启用了帮助文档:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.serviceModel>
<services>
<service name="Demo_rest_ConsoleApp.Service1" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8763/TEST/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="webHttpBinding"
contract="Demo_rest_ConsoleApp.IService1" behaviorConfiguration="ESEndPointBehavior"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="ESEndPointBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceThrottling maxConcurrentCalls="1" maxConcurrentInstances="1" maxConcurrentSessions="1"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
如果问题仍然存在,请随时告诉我。