So I am very new to the whole .NET world, so I could very well have some terminology off. I was asked to help with making some changes to this code because I've helped with some other dev work (entirely different systems). Anyway, I can't even get it to run on my test system to begin the actual work - yet they are already using this code in production so I'm assuming it's just an inconsistency in my setup. Either way though I'm trying to drill down into the code to both learn it better and hopefully understand what could be going wrong with my system.
So this API does not have a front end, all of the testing is being done from Postman. It's supposed to post a request with an XML body to a function that then reads the XML and retrieves data. For whatever reason the request that is passed in always comes up NULL, though I think I verified that Postman is submitting the data because I tried the third answer here: Getting raw POST data from Web API method and I do see the full body of the request then.
Here is the method it is posting to:
[Route("summary")]
[ResponseType(typeof(SummarySearchResponseType))]
public IHttpActionResult PostSummary([FromBody] SummarySearchRequestType req)
{
try
{
var response = _searchService.GetSummary(req);
if (response == null)
{
return BadRequest();
}
return Ok(response);
}
catch
{
return StatusCode(System.Net.HttpStatusCode.InternalServerError);
}
}
Here is that SearchService function:
public SummarySearchResponseType GetSummary(SummarySearchRequestType request)
{
Serilog.Log.Information("GetSummary request = {0}", request);
// Validate required fields in request
if (request == null)
{
Serilog.Log.Logger.Warning("One or more required search fields are missing");
return null;
}
if (string.IsNullOrEmpty(request.ClientNumber))
{
Serilog.Log.Logger.Warning("Missing required search field 'ClientNumber'");
return null;
}
if (request.LossDate == null)
{
Serilog.Log.Logger.Warning("Missing required search field 'LossDate'");
return null;
}
var response = new SummarySearchResponseType
{
RequestID = request.RequestID
};
try
{
using (IMultipleResults sprocResults = _dataContext.UspGetDetailedResponse(
request.ClientNumber,
request.PolicyNumber,
request.PolicySuffix,
request.ClientAccountNum,
request.LossDate.ToShortDateString(),
request.PolicyType,
request.LineCode,
request.AgencyCode,
request.Searchtype,
request.Lob,
request.InsuredSearch?.FirstName,
request.InsuredSearch?.LastName,
request.InsuredSearch?.FullName,
request.InsuredSearch?.DBAName,
request.InsuredSearch?.Address.Address1,
request.InsuredSearch?.Address.Address2,
request.InsuredSearch?.Address.City,
request.InsuredSearch?.Address.State,
request.InsuredSearch?.Address.PostalCode,
request.InsuredSearch?.Address.County,
request.InsuredSearch?.Address.Country,
request.InsuredSearch?.ClientAccountnumber,
request.InsuredSearch?.Email,
request.InsuredSearch?.Phone,
request.InsuredSearch?.Comment,
request.RiskUnitSearch?.RiskUnitID,
request.RiskUnitSearch?.RiskUnitName,
request.RiskUnitSearch?.LocationSearch?.BuildingID,
request.RiskUnitSearch?.LocationSearch?.Address?.Address1,
request.RiskUnitSearch?.LocationSearch?.Address?.Address2,
request.RiskUnitSearch?.LocationSearch?.Address?.City,
request.RiskUnitSearch?.LocationSearch?.Address?.State,
request.RiskUnitSearch?.LocationSearch?.Address?.PostalCode,
request.RiskUnitSearch?.LocationSearch?.Address?.County,
request.RiskUnitSearch?.LocationSearch?.Address?.Country,
request.RiskUnitSearch?.VehicleSearch.VIN,
request.RiskUnitSearch?.VehicleSearch.Year,
request.RiskUnitSearch?.VehicleSearch.Make))
{
// Policies
//
var result1 = sprocResults.GetResult<UspGetDetailedResponseResult1>();
var policies = _mapper.Map<IEnumerable<PolicyType>>(result1).ToArray();
// Insured
//
var result2 = sprocResults.GetResult<UspGetDetailedResponseResult2>();
var insured = _mapper.Map<IEnumerable<ParticipantType>>(result2).ToArray();
//Risk Unit
//
var result3 = sprocResults.GetResult<UspGetDetailedResponseResult3>();
var riskUnits = _mapper.Map<IEnumerable<RiskUnitType>>(result3).ToArray();
// Attach Participants and RiskUnits to Policies via PolicyNumber
//
policies.ToList().ForEach(p =>
{
p.Participants = insured.Where(i => i.PolicyNumber == p.PolicyNumber).ToArray();
p.RiskUnits = riskUnits.Where(i => i.PolicyNumber == p.PolicyNumber).ToArray();
});
response.Policies = policies;
response.PolicyCnt = policies.Length.ToString();
Serilog.Log.Information("GetSummary response = {0}", response);
return response;
}
}
catch (Exception ex)
{
Serilog.Log.Error(ex, $"{ex}", ex);
throw ex;
}
}
And here is the SummarySearchRequestType:
public partial class SummarySearchRequestType
{
public override string ToString()
{
XmlSerializer responseSerializer = new XmlSerializer(this.GetType());
using (StringWriter responseWriter = new StringWriter())
{
responseSerializer.Serialize(responseWriter, this);
var xmlResponse = responseWriter.ToString();
return xmlResponse;
}
}
}
And the rest of it:
public partial class SummarySearchRequestType {
private string requestIDField;
private string clientNumberField;
private string policyNumberField;
private string policySuffixField;
private string clientAccountNumField;
private System.DateTime lossDateField;
private bool lossDateFieldSpecified;
private string policyTypeField;
private string lineCodeField;
private InsuredSearchType insuredSearchField;
private RiskUnitSearchType riskUnitSearchField;
private string agencyCodeField;
private string searchtypeField;
private string lobField;
/// <remarks/>
public string RequestID {
get {
return this.requestIDField;
}
set {
this.requestIDField = value;
}
}
/// <remarks/>
public string ClientNumber {
get {
return this.clientNumberField;
}
set {
this.clientNumberField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string PolicyNumber {
get {
return this.policyNumberField;
}
set {
this.policyNumberField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string PolicySuffix {
get {
return this.policySuffixField;
}
set {
this.policySuffixField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string ClientAccountNum {
get {
return this.clientAccountNumField;
}
set {
this.clientAccountNumField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="date")]
public System.DateTime LossDate {
get {
return this.lossDateField;
}
set {
this.lossDateField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool LossDateSpecified {
get {
return this.lossDateFieldSpecified;
}
set {
this.lossDateFieldSpecified = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string PolicyType {
get {
return this.policyTypeField;
}
set {
this.policyTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string LineCode {
get {
return this.lineCodeField;
}
set {
this.lineCodeField = value;
}
}
/// <remarks/>
public InsuredSearchType InsuredSearch {
get {
return this.insuredSearchField;
}
set {
this.insuredSearchField = value;
}
}
/// <remarks/>
public RiskUnitSearchType RiskUnitSearch {
get {
return this.riskUnitSearchField;
}
set {
this.riskUnitSearchField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string AgencyCode {
get {
return this.agencyCodeField;
}
set {
this.agencyCodeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string Searchtype {
get {
return this.searchtypeField;
}
set {
this.searchtypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace="http://sedgwickcms.com/claims/entities/Policy/v1310")]
public string Lob {
get {
return this.lobField;
}
set {
this.lobField = value;
}
}
}
And in Postman I'm sending a post to the server with this raw XML body:
<?xml version="1.0" encoding="utf-8" ?><SummarySearchRequest xmlns="***">
<RequestID>***</RequestID> <ClientNumber>***</ClientNumber> <LossDate>***</LossDate> <PolicyNumber xmlns="***">***</PolicyNumber>
</SummarySearchRequest>
NOTE - I replaced specific data with ***.
Postman is hitting the server, and like I said I was able to verify based on that other post that actual data is getting to the server, but somewhere it is not setting the object properly (or something else). This is running on a VM of windows 11, through IIS Express in Visual Studio which automatically serves the https on port 44375 if that matters. I'd appreciate any insight into what could be the issue, if you need any more information please let me know - I do not understand .NET well yet. Thank you!