WCF中的基址问题 [英] Baseaddress problem in wcf

查看:104
本文介绍了WCF中的基址问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,


我对wcf概念有些疑问.我在控制台应用程序中创建了服务"WCFService".然后在单独的接口文件中创建了接口"IArea".然后将方法实现为另一个类名"areaservice".尝试运行此服务,但无法运行.我认为uri基址有错误.我对基址没有太多要求,如何放置基址和端口号,是否有任何默认程序?我不知道如何将端口号放入基址中,所以请清除我的疑问.下面我发送了我的代码.


服务名称-> WCFService
界面-> IArea
class-> AreaService


AreaService.cs

Hai ,


I have some doubts in wcf concepts.I have created a service "WCFService" in console application.Then I have created interface"IArea" in a seperate interface file.Then I has implemented the methods into another class names"areaservice".I am trying to run this service but it can''t running.I think there is an error in uri base address.I do no lot about base address.How can we put base address and port number.Is there is any default procedure for this.I do no about how we put port number in base address.So plz clear my doubts.Below I have send my code.


Service name->WCFService
Interface->IArea
class->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



IArea.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace WCFService
{
    [ServiceContract(Namespace="http://WCFService")]
   public interface IArea
    {
        [OperationContract]
        double areaofrectangle(double length, double width);
        [OperationContract]
        double areaofcircle(double radius);
    }
}



program.cs



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() ;
            }
        }
    }
}

推荐答案

我建​​议检查您的web.config文件(或app.config)以获取有关在创建时为您设置的默认值的更多信息该项目.

您收到什么错误,使您相信它是基地址?

确保正确装饰类/方法.确保您的界面公开相同的方法.

这是一个介绍性的介绍,可以帮助您入门.
http://invalidcast.com/2010/04/a-gentle-introduction-to-wcf [^ ]

干杯.
I would suggest checking your web.config file (or app.config) for more information on the defaults that were set up for you when you created the project.

What errors are you receiving that are leading you to believe it''s the base address?

Make sure you are decorating your classes/methods correctly. Make sure your interface exposes the same methods.

Here''s an intro with some walkthroughs to get you started.
http://invalidcast.com/2010/04/a-gentle-introduction-to-wcf[^]

Cheers.


这篇关于WCF中的基址问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆