尝试通过HTTP访问服务时出现TCP错误

时间:2015-01-13 16:17:10

标签: c# asp.net .net wcf

我有类库类型项目,名为" HelloWorldService"有这个界面:

namespace HelloWorldService
{
    [ServiceContract]
    public interface IHelloWorldService
    {
        [OperationContract]
        string GetMessage(string message);
    }
}

这节课:

namespace HelloWorldService
{
    public class HelloWorldService : IHelloWorldService 
    {
        public string GetMessage(string message)
        {
            return message;
        }
    }
}

我在我的解决方案中创建了一个网站,并导入了" HelloWorldService"在里面。 因此,这个网站(称为HelloWorldLocal)只有一个bin文件夹,其中包含" HelloWorldService.dll"," HelloWorldService.pdb"在bin文件夹之外有这个web.config文件:

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5.2" />
      <httpRuntime targetFramework="4.5.2" />
    </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment>
      <serviceActivations>
        <add factory="System.ServiceModel.Activation.ServiceHostFactory"
             relativeAddress="./HelloWorldLocal/HelloWorldLocal.svc" service="HelloWorldService.HelloWorldService"/>
      </serviceActivations>
    </serviceHostingEnvironment>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

现在,我通过Visual Studio在&#34;默认网站/ HelloWorldLocal&#34;下发布这个网站。当我尝试访问http://localhost/HelloWorldLocal/HelloWorldService.svc时,我收到此TCP错误:

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].

想法?

感谢。

2 个答案:

答案 0 :(得分:0)

尝试更改以下行

<add factory="System.ServiceModel.Activation.ServiceHostFactory"
         relativeAddress="./HelloWorldLocal/HelloWorldLocal.svc" service="HelloWorldService.HelloWorldService"/>

<add factory="System.ServiceModel.Activation.ServiceHostFactory"
         relativeAddress="HelloWorldLocal.svc" service="HelloWorldService.HelloWorldService"/>

答案 1 :(得分:0)

我通过打开IIS管理器,点击网站上的右键,然后选择管理应用程序&gt;解决了我的问题。高级设置。

然后在打开的窗口中,出现一个只有http的“Enabled Protocols”属性。我添加了“net.tcp”并且它有效。

不知道为什么,但确实如此。

相关问题