【发布时间】:2011-05-05 23:02:11
【问题描述】:
我正在尝试使用 WCF,但我想我遇到了障碍。我的问题是我可以从“客户端”调用Add(double,double) 和getPerson()。但是,我无法调用 Person 对象的任何方法。我已经用裸方法剥离了这些类。这是我的代码 sn-ps,请让我知道我做错了什么..
Server Code
namespace Test.WebSvc{
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Sample")]
public interface ICalculator
{
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
Person getPerson();
}
public class CalculatorService : ICalculator
{
public double Add(double n1, double n2) { return n1+n2 ; }
public Person getPerson(){
Person tempPerson = new Person();
return tempPerson;
}
}
[DataContract]
public class Person{
[OperationContractAttribute]
public string toString(){
return "This is a Person Object";
}
Client Code
ServiceRef1.CalculatorClient client = ServiceRef1.CalculatorClient();//works
Console.WriteLine(client.Add(1.0,2.0)); //this too works
ServiceRef1.Person p = client.getPerson(); // this is OK., but is not doing what I wanted it to do
Console.WriteLine(p.toString()); // I do not get "This is Person Object"
我猜我的 Person 类的声明有问题.. 但我应该知道我应该做什么或我缺少什么..
谢谢!
【问题讨论】:
标签: wcf web-services serialization object