在ASP.NET中托管时找不到端点

chi*_*ef7 5 asp.net wcf

尝试通过浏览器访问我的服务时,我得到"Endpoint not found"

http://localhost:10093/Services/Service1.svc
Run Code Online (Sandbox Code Playgroud)

尝试从wcftestclient访问同一地址时,我收到"错误:无法从http:// localhost:10093/Services/Service1.svc获取元数据".

如果我在服务实现中放置一个断点,它会被命中,所以我假设svc文件设置正确:

<%@ ServiceHost Language="C#" Debug="true" 
Service="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service" 
Factory="CommonServiceFactory.WebServiceHostFactory,CommonServiceFactory" %>
Run Code Online (Sandbox Code Playgroud)

这是我的配置:

<system.serviceModel>
    <services>
      <service name="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service"
               behaviorConfiguration="MainServiceBehavior">
        <endpoint name="newEndpoing" 
             binding="basicHttpBinding" bindingConfiguration=""
             contract="MyApp.Core.Service.IMyAppService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MainServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

mar*_*c_s 5

所以你有一个*.svc文件来托管你的服务.您可以右键单击该文件上的Visual Studio并说"在浏览器中显示"吗?你在那里得到任何东西,还是立即抛出错误?

下一步:您的服务端点没有address=""属性,我认为这是必须的 - 尝试添加(即使您没有在其中指定地址).

如果您在IIS中托管,则您的服务地址由存在SVC文件的虚拟目录和SVC文件本身定义 - 您可能无法定义特定端口或任何内容(IIS将处理该端口).

所以尝试连接到

http://localhost/Services/Service1.svc
Run Code Online (Sandbox Code Playgroud)

这有用吗?

更新:再次阅读你的帖子,你正在为服务指定一个特殊的工厂 - WebServiceHostFactory.这是WebServiceHostFactory.NET提供的默认值,还是你自己构建的?

重点是:.NET WebServiceHostFactory将使用webHttpBindingRESTful WCF服务 - 这将不适用于端点指定basicHttpBinding,REST服务也不会有任何元数据....

更新#2:尝试在SVC文件和配置文件中仅使用服务的完全限定类名,但不使用程序集规范.

所以改变这个:

Service="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service" 
Run Code Online (Sandbox Code Playgroud)

对此:

Service="MyApp.Core.Service.Service.MyAppService" 
Run Code Online (Sandbox Code Playgroud)

SVC文件:

<%@ ServiceHost Language="C#" Debug="true" 
Service="MyApp.Core.Service.Service.MyAppService" %>
Run Code Online (Sandbox Code Playgroud)

配置文件:

<services>
  <service name="MyApp.Core.Service.Service.MyAppService"
           behaviorConfiguration="MainServiceBehavior">
     <endpoint name="newEndpoing" 
          binding="basicHttpBinding" bindingConfiguration=""
          contract="MyApp.Core.Service.IMyAppService" />
  </service>
</services>
Run Code Online (Sandbox Code Playgroud)


小智 5

在您的解决方案资源管理器上,.svc使用“查看标记”打开您的解决方案,确保您有以下内容:

... ServiceHost Language="C#" Debug="true" 
    Service="Yourservice.yourservice" CodeBehind="yourservice.svc.cs" %>
Run Code Online (Sandbox Code Playgroud)

Yourservice您的命名空间在哪里,yourservice是您.svc创建的名称。