gpt4 book ai didi

c# - 不一致的可访问性 : Parameter type is less accessible than method with WCF MEX

转载 作者:行者123 更新时间:2023-11-30 20:05:44 33 4
gpt4 key购买 nike

我正在做作业,我收到这个错误:

Error 1 Inconsistent accessibility: parameter type 'MexWcfService.MyComplex' is less accessible than method 'MexWcfService.Calculator.complex_sum(MexWcfService.MyComplex, MexWcfService.MyComplex)' E:\North Central College\CSC615\lab8\MexWcfService\MexWcfService\Program.cs 75 26 MexWcfService

下面是我的代码。我的问题发生在 ..public MyComplex complex_sum(MyComplex a, MyComplex b) 的接口(interface)实现类中...

有人能帮帮我吗?我是 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();


}
}
}

最佳答案

您需要将“MyComplex”类声明为公共(public)类,因为您已经在类计算器的公共(public)方法中使用了该类型。

关于c# - 不一致的可访问性 : Parameter type is less accessible than method with WCF MEX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10844281/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com