none
求助wcf基础问题(c#与.net3.5高级程序设计(第4版))中例子问题 RRS feed

  • 问题

  • 求助wcf基础问题(c#与.net3.5高级程序设计(第4版))中例子问题

    我最近在学习wcf,看了这本书中695——705的基础例子。使用的是是win7+vs2010。也有管理员权限。开启了元数据交换,服务主机可以启动,服务的状态也是open。但是在ie上无法察看,在做客户端服务引用时,会出现

    ***********************

    无法连接到远程服务器
    由于目标计算机积极拒绝,无法连接。 127.0.0.1:9080
    元数据包含无法解析的引用:“http://localhost:9080/MagicEightBallService/”。
    没有终结点在侦听可以接受消息的 http://localhost:9080/MagicEightBallService。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参见 InnerException 以了解详细信息。
    无法连接到远程服务器
    由于目标计算机积极拒绝,无法连接。 127.0.0.1:9080
    如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。

    *****************的错误

    代码如下:这个是服务端程序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using MagicEightBallServiceLib;
    namespace MagicEightBall_ServiceHost
    {
     class Program
     {
      static void Main(string[] args)
      {
       Console.WriteLine("wcf");
    
       using (ServiceHost serviceHost = new ServiceHost(typeof(MagicEightBallService)))
       {
        serviceHost.Open();
        Console.WriteLine("the service is ready.");
        Console.WriteLine("press the enter key to terminate service.");
        displayHostInfo(serviceHost);
       }
       
       Console.ReadLine();
      }
      static void displayHostInfo(ServiceHost host)
      {
       Console.WriteLine("hostinfo");
       Console.WriteLine("name: {0}",host.State);
       Console.WriteLine("port: {0}",host.BaseAddresses[0].Port);
       Console .WriteLine ("localpath: {0}",host .BaseAddresses [0].LocalPath);
       Console .WriteLine ("Uri: {0}",host .BaseAddresses [0].AbsoluteUri);
       Console.WriteLine ("scheme: {0}",host.BaseAddresses [0].Scheme );
      }
     }
    }
    
    这个是app。config文件
    <pre lang="x-xml"><?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <system.serviceModel>
     <services>
      <service name="MagicEightBallServiceLib.MagicEightBallService"
      behaviorConfiguration = "EightBallServiceMEXBehavior">
      <endpoint address =""
      binding="basicHttpBinding"
      contract="MagicEightBallServiceLib.IEightBall"/>
      <!-- Enable the MEX endpoint -->
      <endpoint address="mex"
      binding="mexHttpBinding"
      contract="IMetadataExchange" />
      <!-- Need to add this so MEX knows the address of our service -->
      <host>
       <baseAddresses>
       <add baseAddress ="http://localhost:9080/MagicEightBallService"/>
       </baseAddresses>
      </host>
      </service>
     </services>
     <!-- A behavior definition for MEX -->
     <behaviors>
      <serviceBehaviors>
      <behavior name="EightBallServiceMEXBehavior" >
       <serviceMetadata httpGetEnabled="true" />
      </behavior>
      </serviceBehaviors>
     </behaviors>
     </system.serviceModel>
    </configuration>
    
    这个是服务的代码
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    namespace MagicEightBallServiceLib
    {
     public class MagicEightBallService:IEightBall
     {
      public MagicEightBallService()
      {
       Console.WriteLine("the 8-ball awaits your question...");
      }
      public string ObtainAnswerToQuestion(string userQuestion)
      {
       string[] answer = {
             "future uncertain", "yes", "no", 
             "hazy", "ask again later", "definity" };
       Random r = new Random();
       return string.Format("{0}?{1}.", userQuestion, answer[r.Next(answer.Length)]);
      }
     }
     [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
     public interface IEightBall
     {
      [OperationContract]
      string ObtainAnswerToQuestion(string userQuestion);
     }
    }
    
    
    我察看了别人的问题,也察看了自己的add。啥的都没有错,可以就是看不了网页,求助各位大虾。
    2011年1月24日 4:28

答案

全部回复