开发者

Webreference vs servicereference. Only one works ? Serialization?

I've got two applications.

One uses webreference to my webservice, and second use servicereference to my webservice.

There is metohod which I'm invoking:

[WebMethod]
public Car[] GetCars(string carCode)
{
 Cars[] cars= ModelToContract.ToCars(MyFacade.GetCars(carCode);
return cars;
}

Car has two pools:

开发者_运维百科
string Code {get;set;}
CarType Type {get;set;}

public enum CarType
{
Van=0,
Pickup=1
}

I'm debuging this webMethod, and...

at the end webservice throw good collection of cars, which has one car: code="bmw",Type.Van

But... Application with webrefence receives the same collection and application with servicereference gets collection, where field code is null...

Invoking servicereference:

MyService myService=new MyService()
Cars[] cars= client.GetCars(carcode);

Invoking webservice:

MyService.MyServiceSoapClient client = new MyServiceS.MyServiceSoapClient();
            Cars[] cars= client.GetCars(carcode);


Hum it's a serialization problem.

Your model should be like this :

[Serializable]
public class Car
{
    [XmlElement]
    string Code {get;set;}

    [XmlElement]
    CarType Type {get;set;}
}

You may ensure the return type too :

MyService myService=new MyService()
MyService.Car[] cars= myService.GetCars(carcode);

-

MyServiceS.MyServiceSoapClient client = new MyServiceS.MyServiceSoapClient();
MyServiceS.Car[] cars= client.GetCars(carcode);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜