可访问性不一致:参数类型比使用WCF MEX的方法更难访问

use*_*044 2 c# wcf web-services mex

我正在进行任务,我收到此错误:

错误1可访问性不一致:参数类型 'MexWcfService.MyComplex' 大于法 'MexWcfService.Calculator.complex_sum(MexWcfService.MyComplex,MexWcfService.MyComplex)' E不易进入:\北环学院\ CSC615\lab8\MexWcfService\MexWcfService \计划. cs 75 26 MexWcfService

以下是我的代码.我的问题出现在..public MyComplex complex_sum(MyComplex a,MyComplex b)的接口实现类中...

有人可以帮助我.我是C#的新手,更不用说带有元数据交换端点的WCF.任何指针都将非常感激.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.ServiceModel.Description;

namespace MexWcfService
{
    [DataContract]
    class MyComplex
    {
        int real;
        int im;
        public MyComplex(int real, int im)
        {
            Real = real;
            Im = im;
        }

        [DataMember]
        public int Real
        {
            get { return real; }
            set { real = value; }
        }
        [DataMember]
        public int Im
        {
            get { return im; }
            set { im = value; }
        }

    }
    [ServiceContract]
    interface ICalculator
    {
        [OperationContract]
        int mult(int a, int b);

        [OperationContract]
        List<int> fib(int n);

        [OperationContract]
        MyComplex complex_sum(MyComplex a, MyComplex b);
    }

    public class Calculator : ICalculator
    {

        public int mult(int a, int b)
        {
            int total = (a * b);
            return total;
        }
        public List<int> fib(int n)
        {
            List<int> list = new List<int>();
            for (int i = 0; i < n; i++)
            {
                int a = 0;
                int b = 1;
                for (int q = 0; q < i; q++)
                {
                    int temp = a;
                    a = b;
                    b = temp + b;
                }
                list.Add(a);
            }

            return list;
        }
        public MyComplex complex_sum(MyComplex a, MyComplex b)
        {
            int real = (a.Real + b.Real);
            int im = (a.Im + b.Im);

            MyComplex complex = new MyComplex(real, im);
            return complex;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(Calculator), new Uri("http://localhost:50000/Math"));
            host.AddServiceEndpoint(typeof(Calculator), new BasicHttpBinding(), "mult");
            ServiceMetadataBehavior bhv = new ServiceMetadataBehavior();
            bhv.HttpGetEnabled = true;
            host.Description.Behaviors.Add(bhv);
            host.Open();
            Console.ReadLine();


        }
    }
}
Run Code Online (Sandbox Code Playgroud)

RJ *_*han 7

您需要将类"MyComplex"声明为public,因为您已在类Calculator中使用公共方法中的类型.