在ASP.NET托管时,端点未找到

5
当我尝试通过浏览器访问我的服务时,出现了“Endpoint not found”的错误提示。
http://localhost:10093/Services/Service1.svc

当我尝试从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" %>

这是我的配置:

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

这是一个带问题的样本项目 - http://www.nippyzip.com/uploads/101003074000-57717.zip - chief7
我有同样的问题。没有终结点,无法为我的Silverlight应用程序生成客户端。 - Ievgen
5个回答

5
您有一个*.svc文件来托管您的服务。您是否可以在Visual Studio中右键单击该文件并选择“在浏览器中显示”?您会得到什么,还是它会立即抛出错误?
接下来:您的服务终结点没有address=""属性,我认为这是必需的-尝试添加(即使您没有在其中指定地址)。
如果您在IIS中托管,则服务地址由SVC文件所在的虚拟目录和SVC文件本身定义-您可能无法定义特定的端口或任何内容(IIS将处理此问题)。
因此,请尝试连接至
http://localhost/Services/Service1.svc

有没有可能这样行呢?
更新:仔细阅读您的帖子后,您为该服务指定了一个特殊的工厂 - WebServiceHostFactory。这是.NET提供的默认WebServiceHostFactory,还是您自己构建的?
重点是:.NET WebServiceHostFactory将使用webHttpBinding来进行RESTful WCF服务 - 这不适用于指定basicHttpBinding的端点,也不会有任何元数据...
第二次更新:尝试仅在SVC文件和配置文件中使用服务的完全限定类名,但不包括程序集规范。
所以请将此更改为:
Service="MyApp.Core.Service.Service.MyAppService,MyApp.Core.Service" 

转换为:

Service="MyApp.Core.Service.Service.MyAppService" 

SVC文件:

<%@ ServiceHost Language="C#" Debug="true" 
Service="MyApp.Core.Service.Service.MyAppService" %>

配置文件:

<services>
  <service name="MyApp.Core.Service.Service.MyAppService"
           behaviorConfiguration="MainServiceBehavior">
     <endpoint name="newEndpoing" 
          binding="basicHttpBinding" bindingConfiguration=""
          contract="MyApp.Core.Service.IMyAppService" />
  </service>
</services>

1
添加了空地址,没有变化。尝试使用无端口的URL,收到“Internet Explorer无法显示网页”的消息。这是一个特殊的工厂,但我尝试使用标准主机工厂,却得到了相同的错误。 - chief7
1
@Chief7:只要您无法成功执行“在浏览器中查看”,那么您的服务就存在着重大问题,只有当这个问题得到解决后,您才能够启动该服务。我在答案中更新了一些建议,请尝试一下。 - marc_s
1
@Chief7:好的,在SVC文件中,你可能需要类名加上程序集。但在常规配置文件中,你绝对不应该有除了<service name="MyApp.Core.Service.Service.MyAppService" ....(没有程序集引用)之外的任何内容。 - marc_s
1
同时,已更改为使用System.ServiceModel.Activation.WebServiceHostFactory,但在浏览器中仍然出现“找不到终结点”的错误。 - chief7
1
这里有一个证明,展示了相同的行为:http://www.nippyzip.com/uploads/101003074000-57717.zip - chief7
显示剩余3条评论

5
在解决方案资源管理器中,使用“查看标记”打开您的.svc文件,确保您有以下类似内容:
... ServiceHost Language="C#" Debug="true" 
    Service="Yourservice.yourservice" CodeBehind="yourservice.svc.cs" %>

其中Yourservice是您的命名空间,yourservice是您创建的.svc的名称。


4

当我在浏览器窗口中输入这个时,我得到了相同的结果(终点未找到)。

http://c143253-w7a:2221/ws/myService.svc

然后,当我将整个URL放入方法中时,它能够正常运行。就像这样:

http://c143253-w7a:2221/ws/myService.svc/HelloWorld?theInput=pds

在我的 .svc 文件中,我正在使用这个。
Factory="System.ServiceModel.Activation.WebServiceHostFactory"

我认为工厂只有在需要时才会启动端点。这就是为什么我们在浏览器中看到"Endpoint not found"的原因。

下面是接口代码中方法签名的样式:

using System.ServiceModel.Web;

[WebGet(UriTemplate = "HelloWorld?theInput={theInput}")]
[OperationContract]
string HelloWorld(string theInput);

我没有在webconfig文件中添加任何内容。虽然其中有一些东西,但我认为那是通过使用VS的“Add WCF Service”模板自动生成的。它的样子如下:

<system.serviceModel>
 <behaviors>
   <serviceBehaviors>
     <behavior name="">
       <serviceMetadata httpGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="false" />
     </behavior>
   </serviceBehaviors>
 </behaviors>
 <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

0

我的 web.config 和你的非常相似,针对 WCF 服务,你一定要像 Shiraz 说的那样添加 MEX 端点。我添加了一个行为配置,使任何消息大小都可以通过 WCF。如果这些设置能帮到你,请尝试使用它们(不要忘记更改契约设置):

<system.serviceModel>    
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="524288000" maxBufferPoolSize="524288000" maxReceivedMessageSize="524288000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="500000000" maxStringContentLength="500000000" maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm="">
          <extendedProtectionPolicy policyEnforcement="Never"/>
        </transport>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
 </bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="6553600" />
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="serviceBehavior" name="RC.Svc.Web.TPF.Service">
    <endpoint
       address=""
       binding="basicHttpBinding"
       bindingConfiguration="BasicHttpBinding_IService"
       contract="RC.Svc.Web.TPF.IService" />
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<client />


您还可以使用Visual Studio文件夹中的WcfTestClient.exe轻松测试(Visual Studio 10.0\Common7\IDE\WcfTestClient.exe 和 http://msdn.microsoft.com/en-us/library/bb552364.aspx)。 您需要一个正常工作的MEX端点。 - Animal Mother
1
我定义了一个mex点并尝试将服务添加到wcftestclient中。它说服务已成功添加,但列表中没有添加任何服务。 - chief7

0

1
谢谢您的回答,但添加了Mex终结点后没有任何变化。 - chief7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接