WCF不会托管

时间:2014-11-06 13:02:37

标签: c# wcf host

直截了当地说,我有一个WCF项目和Host项目(我想启动Service),当我将WCF作为一个startUp项目,它托管服务时,我收到一条确认消息(右下角)一切正常,但是当我尝试从Host项目托管时,它没有托管,也没有任何确认消息。

这是我的主机代码:

static void Main(string[] args)
    {
        using (ServiceHost host = new ServiceHost(typeof(MovieService)))
        {

                host.Open();
                Console.WriteLine("The host is online.");
                Console.ReadLine();
                host.Close();
            }


    }

主机app.config:

<system.serviceModel>
<services>
  <service name="CinemaProject.WCF.MovieService">
    <endpoint address="" binding="wsHttpBinding" contract="CinemaProject.WCF.IMovieService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/Design_Time_Addresses/CinemaProject.WCF/MovieService/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

我的WCF代码:

public class MovieService : IMovieService
{
    static MovieCtr movieCtr = new MovieCtr();

    public void Add(Movie movie)
    {
         movieCtr.add(movie);
    }

    public void SearchById(int id)
    {
    }

    public void Update(Movie movie)
    {
    }

    public void Delete(Movie movie)
    {
    }

    public void DeleteById(int id)
    {
    }

    public IEnumerable<MovieDTO> All()
    {
        return movieCtr.All();
    }
}

和WCF app.config:

<system.serviceModel>
<services>
  <service name="CinemaProject.WCF.MovieService">
    <endpoint address="" binding="wsHttpBinding" contract="CinemaProject.WCF.IMovieService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/Design_Time_Addresses/CinemaProject.WCF/MovieService/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="True" />
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>

有人可以看一下并指出我正确的方向,并在可能的情况下发布解决方案。

谢谢你, 马吕斯J。

1 个答案:

答案 0 :(得分:0)

尝试从CMD窗口运行:

netsh http add urlacl url=http://+8733:/ user=DOMAIN\user

指定正确的DOMAIN和用户