我用一個名爲GetLastVehicle()
的WebMethod編寫了一個Web服務,並將它部署在IIS上。當我到瀏覽器中的地址時,我可以看到並使用該方法。如何在ASMX服務客戶端上調用方法
當我將Web服務作爲服務引用添加到我的項目並想要使用它時,我看不到我的方法。取而代之的是GetLastVehicleRequest
,GetLastVehicleRequestBody
,GetLastVehicleResponse
和GetLastVehicleResponseBody
。
這是服務方法:
[WebMethod]
public Vehicle GetLastVehicle()
{
Random rnd = new Random();
Vehicle lastVehicle = new Vehicle();
lastVehicle.ID = rnd.Next();
lastVehicle.StartTimeStr = DateTime.Now.ToString();
lastVehicle.Direction = Convert.ToBoolean(rnd.Next(0, 1));
lastVehicle.VehicleLength = float.Parse(rnd.Next(2, 6).ToString());
lastVehicle.GrossWeight = float.Parse(rnd.Next(1200,12000).ToString());
lastVehicle.Velocity = float.Parse(rnd.Next(50, 140).ToString());
lastVehicle.WheelBase = float.Parse(rnd.Next().ToString());
lastVehicle.AxlesCount = rnd.Next(2, 9);
List<Axle> lastVehicleAxles = new List<Axle>();
for (int i = 0; i < lastVehicle.AxlesCount; i++)
{
Axle axle = new Axle();
axle.Weight = rnd.Next(500, Convert.ToInt32(lastVehicle.GrossWeight/lastVehicle.AxlesCount));
if (i == 0)
axle.Distance = 0;
else
axle.Distance = rnd.Next(1, Convert.ToInt32(lastVehicle.VehicleLength/lastVehicle.AxlesCount) > 1 ? Convert.ToInt32(lastVehicle.VehicleLength/lastVehicle.AxlesCount) : 1);
lastVehicleAxles.Add(axle);
}
lastVehicle.Axles = lastVehicleAxles;
return lastVehicle;
}
我怎樣才能把它從我的客戶?
你可以發佈你的方法聲明嗎? –