返回首页


我曾怀疑在WCF concepts.I一些已创建服务在控制台application.Then"WCFService"我已创建一个单独的接口file.Then接口"IArea"我已经到另一个类的名称"areaservice"实施方法。我试图运行此服务,但它不能running.I认为有一个在URI基地address.I错误不没有基地address.How的很多,我们可以把基地址和端口number.Is有任何的默认程序。我没有关于如何我们把基地address.So PLZ端口号清除我doubts.Below我已经发送给我的代码。
服务名称-GT; WCFService
接口GT; IArea
-GT类; AreaService
AreaService.cs


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace WCFService

{

   public class AreaService:IArea 

    {

       public double areaofrectangle(double length, double width)

       {

           double area = length * width;

           Console.WriteLine("length:{0};width:{1}", length, width);

           Console.WriteLine("Area:{0}", area);

           return area;

       }

       public double areaofcircle(double radius)

       {

           double area = Math.PI * radius;

           Console.WriteLine("radius:{0}", radius);

           Console.WriteLine("Area:{0}", area);

           return area;

       }

    }

}

 


IArea.cs
{C}
Program.cs的

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

using System.ServiceModel.Description;

 

namespace WCFService

{

    class Program

    {

        static void Main(string[] args)

        {

            Uri baseaddress = new Uri("http://localhost:8080/WCFService/Sample");

            ServiceHost selfhost = new ServiceHost(typeof(AreaService), baseaddress);

            try

            {

                selfhost.AddServiceEndpoint(typeof(IArea),new WSDualHttpBinding(),"AreaService");

                ServiceMetadataBehavior smd=new ServiceMetadataBehavior ();

                smd.HttpGetEnabled=true;

                selfhost.Description.Behaviors.Add(smd);

                selfhost.Open();

                Console.WriteLine("service is ready");

                Console.WriteLine("press <enter> key to stop");

                Console.WriteLine();

                Console.ReadLine();

                selfhost.Close();

            }

            catch (CommunicationException ex)

            {

                Console.WriteLine("An Error is occured:{0}", ex.Message);

                selfhost.Abort() ;

            }

        }

    }

}

 

回答

评论会员:T 时间:2