I created a custom web service to accept xml from one of our lead aggregators. However, it is not deserializing the request body, and all I get in response is a Null Object Reference error. Am I missing something?
My custom web service:
namespace Terrasoft.Configuration.UsrMyLeadImportNamespace
{
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Xml.Serialization;
using Core;
using Core.DB;
using Terrasoft.Web.Common;
[XmlSerializerFormat]
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class UsrMyLeadImport: BaseService
{
private SystemUserConnection _systemUserConnection;
private SystemUserConnection SystemUserConnection
{
get
{
return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection);
}
}
// Service operation.
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "new")]
public MyResponse New(LeadInformation leadInformation)
{
var response = new MyResponse();
response.ResponseStatus = "Tracking Number is => " + leadInformation.TrackingNumber;
return response;
}
}
[XmlRoot(ElementName = "LeadInformation")]
public class LeadInformation
{
[XmlElement(ElementName = "TrackingNumber")]
public int TrackingNumber { get; set; }
}
[DataContract(Namespace = "")]
[Serializable]
public class MyResponse
{
[DataMember]
public string ResponseStatus { get; set; }
}
}
Request Body:
12345
Like
I've performed the same setup (additionally to the code you've shared, registered the service as anonymous) and sent the following request in Postman:
As you can see the result is correct so the issue is somewhere in the request you send or in the service settings. You need to double-check them.
I've performed the same setup (additionally to the code you've shared, registered the service as anonymous) and sent the following request in Postman:
As you can see the result is correct so the issue is somewhere in the request you send or in the service settings. You need to double-check them.