无法添加服务。无法连接到远程服务器

时间:2012-06-29 09:26:29

标签: .net wcf exception-handling

我知道这是一个常见问题解答,我已经阅读了所有类似的Q和A,但我仍然没有做好。

我是Web服务和ASP.NET的新手。我有一个由同事编写的小型WCF服务应用程序,该应用程序在他的电脑上工作并进行了演示。在我的电脑上,没有任何变化,我无法让它在作为服务添加时被WCF测试客户端程序接受(下面的错误消息)。我的同事现在休假了!

项目属性设置为使用带有自动分配端口号的VS开发服务器启动WcfTestClient.exe。该项目添加了webform.aspxGlobal.asax文件,这些文件是服务所必需的。

我跑了

netsh http add urlacl url=http://localhost:51568/Service1.svc user=<loginname>

我的问题是如何通过WcfTestClient启动服务,以及浏览器上的webform?

我已经查看了类似问题的各种SO答案,但我仍然感到难过。

  

无法添加服务。可能无法访问服务元数据。使   确保您的服务正在运行并公开元数据。错误:不能   从http://localhost:51568/Service1.svc获取元数据如果是这样的话   您可以访问的Windows(R)Communication Foundation服务,   请检查您是否启用了元数据发布   指定地址。有关启用元数据发布的帮助,请   参考...错误URI:http://localhost:51568/Service1.svc
  元数据包含无法解析的引用:   'http://localhost:51568/Service1.svc'。没有端点   在http://localhost:51568/Service1.svc听,可以接受   信息。这通常是由错误的地址或SOAP操作引起的。   有关更多详细信息,请参阅InnerException(如果存在)。无法连接   到远程服务器因为目标,无法建立连接   机器主动拒绝它127.0.0.1:51568HTTP GET错误URI:   http://localhost:51568/Service1.svc下载时出错   'http://localhost:51568/Service1.svc'。无法连接到   远程服务器因为目标,无法建立连接   机器主动拒绝它127.0.0.1:51568

这是我的web.config:

<system.web>
    <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
    <services>
        <service name="Service1" behaviorConfiguration="DefaultBehavior">
            <endpoint address="http://localhost:*/Service1" binding="basicHttpBinding" contract="IService1" />
            <endpoint address="http://localhost:*/Service1/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="DefaultBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

关于端口号,我觉得奇怪的是,如果我没有将项目设置为从外部程序开始,那么浏览器会在localhost端口50345列出目录列表,该端口号是51568的不同端口号。

1 个答案:

答案 0 :(得分:0)

  

无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:51568

  

如果我没有将项目设置为从外部程序开始,那么浏览器会在localhost端口50345列出目录列表

这仅表示您的WCF服务托管在后一个端口。您可以在项目属性的“Web”选项卡上进行更改。

相关问题