0
我正在處理一個任務,我收到了這個我不明白的錯誤。我正在爲一個工作服務編寫一個WCF客戶端。有人可以幫我從這裏出去嗎?WCF客戶端產生的錯誤我不知道
此行引發錯誤:
MyComplex sumcplx = proxy.complex_sum(one,two);
錯誤,我得到
Error: The best overloaded method match for 'NETProxyWCFClient.ProxyTypes.CalculatorClient.complex_sum(NETProxyWCFClient.ProxyTpes.MyComplex,NETProxyWCFClient.ProxyTpes.MyComplex)' has some invalid arguments
代碼到我的程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
namespace NETProxyWCFClient
{
[DataContract]
public class MyComplex
{
int real;
[DataMember]
public int Real
{
get { return real; }
set { real = value; }
}
[DataMember]
int im;
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);
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter in 2 numbers");
string read = Console.ReadLine();
string[] numbers = read.Split(' ');
int m = int.Parse(numbers[0]);
int n = int.Parse(numbers[1]);
ProxyTypes.CalculatorClient proxy = new ProxyTypes.CalculatorClient();
//Multiplcation
int sum = proxy.mult(m, n);
Console.WriteLine(sum.ToString());
//Mycomplex
MyComplex one = new MyComplex();
one.Im = m;
one.Real = n;
MyComplex two = new MyComplex();
two.Im = n;
two.Real = m;
MyComplex sumcplx = proxy.complex_sum(one,two);
Console.WriteLine(sumcplx.Im + " , " + sumcplx.Real);
//fib one
int[] listM = proxy.fib(m);
foreach (int listItem in listM)
{
Console.Write(listItem.ToString() + " ");
}
Console.WriteLine("");
//fib 2
int[] listN = proxy.fib(n);
foreach (int listItem in listN)
{
Console.Write(listItem.ToString() + " ");
}
Console.ReadLine();
}
}
}
如果所有代碼都在一個項目中,則不會從代碼中完全清除。你有2個項目:一個WCF項目和一個控制檯EXE? 如果不是:完全限定(瓦特/命名空間)在你的減速變化1和2。 HTH –
這是客戶端的代碼...我寫的服務具有完全相同的類和接口..兩個控制檯項目 – user975044
如果您已經爲測試程序添加了服務引用,那麼有一個proxt類是爲你生成的。如果你有ICalculator定義的明確性(你寫的代碼)將其刪除。它已經在您的項目中的NETProxyWCFClient.ProxyTpes.MyComplex,NETProxyWCFClient.ProxyTpes命名空間下。 –