简体   繁体   English

WCF AJAX 启用服务创建正常,但方法返回 404

[英]WCF AJAX enabled service created OK, but method returns 404

This is my first WCF service, so please be understanding.这是我的第一个 WCF 服务,请谅解。 :) :)

  • I have an existing ASP.Net web site that has been running OK so far.我有一个现有的 ASP.Net web 站点,到目前为止运行良好。
  • Using VS 2017 I added a new WCF Ajax enabled service.使用 VS 2017,我添加了一个新的 WCF Ajax 启用服务。
  • VS created the.svc and.cs files and it also made cahnges to the web.config. VS 创建了 .svc 和 .cs 文件,它还对 web.config 进行了更改。
  • I made sure that HTTP activation is enabled in server roles.我确保在服务器角色中启用了 HTTP 激活。

When navigating to the service url via browser, the service page loads.通过浏览器导航到服务 url 时,会加载服务页面。 OK.好的。 When I try to add "/DoWork" to access the method that was created as the default, i get a 404 error.当我尝试添加“/DoWork”以访问默认创建的方法时,我收到 404 错误。

I have been going CRAZY trying different tutorial suggestions.我一直在疯狂尝试不同的教程建议。 NOTHING WORKS.没有任何效果。 I must be missing something simple.我一定错过了一些简单的东西。 Something maybe is not enabled at server level?服务器级别可能未启用某些内容? I would think that the WCF code that was added by VS would work as it, right?我认为VS添加的WCF代码可以正常工作,对吗?

WHY 404?????为什么是404?????? What am I missing????我错过了什么????

Thank you for any help and best regards,感谢您的任何帮助和最好的问候,

Udar乌达尔

Here is the relevant section of web.config这是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>

If you use webhttpbinding, you need to add webHttp to the endpoint behavior:如果使用 webhttpbinding,则需要在端点行为中添加 webHttp:

<endpointBehaviors>
                <behavior name="ESEndPointBehavior">
                    <webHttp/>
                </behavior>
</endpointBehaviors>

This is my configuration file, and I enabled the help document:这是我的配置文件,我启用了帮助文档:

<?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>

在此处输入图像描述

Feel free to let me know if the problem persists.如果问题仍然存在,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM