Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ASP.NET中托管时未找到终结点_Asp.net_Wcf - Fatal编程技术网

在ASP.NET中托管时未找到终结点

在ASP.NET中托管时未找到终结点,asp.net,wcf,Asp.net,Wcf,当我试图通过以下位置的浏览器访问我的服务时,会得到“未找到端点” http://localhost:10093/Services/Service1.svc 尝试从wcftestclient访问同一地址时,我收到“错误:无法从中获取元数据” 如果我在服务实现中放置断点,它将被命中,因此我假设svc文件设置正确: <%@ ServiceHost Language="C#" Debug="true" Service="MyApp.Core.Service.Service.MyAppServi

当我试图通过以下位置的浏览器访问我的服务时,会得到“未找到端点”

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

如果我在服务实现中放置断点,它将被命中,因此我假设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>

因此您有一个*.svc文件来承载您的服务。您能在VisualStudio中右键单击该文件并说“在浏览器中显示”吗?你在那里得到了什么,或者它会马上抛出一个错误吗

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

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

所以试着连接到

http://localhost/Services/Service1.svc
这有可能奏效吗

更新:再次仔细阅读您的帖子,您为服务指定了一个特殊的工厂-
WebServiceHostFactory
。这是.NET提供的默认
WebServiceHostFactory
,还是您自己构建的东西

要点是:.NET
WebServiceHostFactory
将对RESTful WCF服务使用
webHttpBinding
,这不适用于指定
basicHttpBinding
的端点,REST服务也不会有任何元数据

更新#2:尝试在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>

配置文件:

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

错误消息为“无法获取元数据”,并且未定义MetadataExchange端点。您确实有httpGetEnabled=“True”,这也是必需的


请尝试定义MEX端点,以了解如何查看的详细信息:

我的WCF服务的my web.config与您的非常相似。你一定要像设拉子说的那样添加MEX端点。我添加了一个行为配置,允许任何消息大小通过WCF。如果可以帮助您,请尝试使用这些设置(不要忘记更改合同设置):



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

... ServiceHost Language="C#" Debug="true" 
    Service="Yourservice.yourservice" CodeBehind="yourservice.svc.cs" %>
其中,
Yourservice
是您的名称空间,
Yourservice
是您创建的
.svc
的名称。

当我将其放入浏览器窗口时,我得到了相同的结果(未找到端点)

http://c143253-w7a:2221/ws/myService.svc
然后,当我将整个url放入该方法时,它运行良好。像这样

http://c143253-w7a:2221/ws/myService.svc/HelloWorld?theInput=pds
在我的.svc文件中,我使用的是

Factory="System.ServiceModel.Activation.WebServiceHostFactory"
我认为工厂在需要时才会启动端点。这就是为什么我们在浏览器中找不到端点(?)

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

using System.ServiceModel.Web;

[WebGet(UriTemplate = "HelloWorld?theInput={theInput}")]
[OperationContract]
string HelloWorld(string theInput);
我没有在网络配置中添加任何内容。有一些东西在那里,但我认为这是来自于VS,添加WCF服务模板。看起来是这样的:

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


添加了空地址,没有更改。尝试没有端口的url,收到“Internet Explorer无法显示网页”这是一个特殊的工厂,但我尝试使用标准主机工厂,得到了相同的结果error@Chief7:只要您无法成功执行“在浏览器中查看”,您的服务就会出现严重问题,并且只要该问题不起作用,您就无法启动该服务。更新了我的答案,增加了一些建议供尝试out@Chief7:好的,在SVC文件中,您可能需要类名加上程序集。但是在常规配置文件中,您肯定应该没有任何东西,除了
之外,还更改为使用System.ServiceModel.Activation.WebServiceHostFactory,并且在浏览器中仍然得到“Endpoint not found”(未找到端点)。这是exibists具有相同行为的证明,这是一个有此问题的示例项目-我有相同的问题。如果没有终结点,则无法为我的silverlight应用程序生成客户端。答案为anks,但在添加mex终结点后没有更改。您还可以使用Visual Studio文件夹中的WcfTestClient.exe轻松进行测试(Visual Studio 10.0\Common7\IDE\WcfTestClient.exe和)。您需要一个工作的MEX端点。我已定义了一个MEX点,并尝试将服务添加到wcftestclient。我说服务已成功添加,但没有将任何服务添加到列表中。