当前位置: 代码迷 >> Web Service >> 请问一个wcf服务添加失败的有关问题
  详细解决方案

请问一个wcf服务添加失败的有关问题

热度:684   发布时间:2013-06-25 23:45:42.0
请教一个wcf服务添加失败的问题。
我创建了一个服务,这个服务有四个终结点。配置如下 :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Service.Calculator" behaviorConfiguration="servicebehavior">
        <endpoint address="mex" binding="wsHttpBinding" contract="Service.ICalculator"></endpoint>
        <endpoint address="mex" binding="netTcpBinding" contract="Service.ICalculator"></endpoint>
        <endpoint address="http://localhost:8000/test" binding="wsHttpBinding" contract="Service.ICalculator"></endpoint>
        <endpoint address="net.tcp://localhost:8001/test" binding="netTcpBinding" contract="Service.ICalculator"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8002/"/>
            <add baseAddress="net.tcp://localhost:8003"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="servicebehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

然后启动服务
 using (ServiceHost host = new ServiceHost(typeof(Service.Calculator)))
            {
                host.Opened += delegate
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("服务已经开启!{0}",host.State);
                    Console.Read();
                };

                host.Open();
            }

我在一个控制台项目中添加服务引用,提示如下:
下载“http://localhost:8000/test”时出错。
请求因 HTTP 状态 400 失败: Bad Request。
元数据包含无法解析的引用:“http://localhost:8000/test”。
元数据包含无法解析的引用:“http://localhost:8000/test”。
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。

但是使用编程的方式调用却可以。
  相关解决方案