Create WSDl file through web service URL and save it
open visual studion and add service reference
Code
For Serlization
public static string SerializeObject<T>(this T toSerialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, toSerialize);
return textWriter.ToString();
}
}
public static T DeSerializeObject<T>(this T toSerialize, string serializedData)
{
XmlSerializer deserializer = new XmlSerializer(toSerialize.GetType());
using (TextReader tr = new StringReader(serializedData))
{
T deserializedPerson = (T)deserializer.Deserialize(tr);
return deserializedPerson;
}
}
For Access The Sap API
public ZbapiMmoeWaterResponse GetWaterTankDetail(string vehicleno)
{
ZbapiMmoeWater objWaterRequest = new ZbapiMmoeWater
{
Vehicleno = vehicleno
};
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress endpoint = new EndpointAddress(ConstantHelper.WaterTanlApiUrl);
ZSESA_WATER_TANKER_interfaceClient client = new ZSESA_WATER_TANKER_interfaceClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = ConstantHelper.SapUserName;
client.ClientCredentials.UserName.Password = ConstantHelper.SapPassword;
ZbapiMmoeWaterResponse objWaterResponse = client.ZbapiMmoeWater(objWaterRequest);
return objWaterResponse;
}
For WebApi Acode
public class WaterTankApiController : ApiController
{
[Route("WaterTankApi/GetVehcileDetail/{VehcileNo}")]
public string GetVehcileDetail(string VehcileNo)
{
var objWaterTank = (new WaterTankOperation()).GetVehcileDetail(VehcileNo);
var ObjSerializer = new JavaScriptSerializer();
string json = ObjSerializer.Serialize(objWaterTank);
return json;
}
}