Hello,
I created a simple Webservice that works for some requests, but fails for others. Specifically, when the following POST request is sent to the server, it works:
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<acceptCharge xmlns="http://sample.ws.com/">
<request>
<RequestID>12648638354235</RequestID>
<ChargeAmount>$12.98</ChargeAmount>
<ChargeDate>2020-05-01T11:38:19.209Z</ChargeDate>
</request>
</acceptCharge>
</S:Body>
</S:Envelope>
However, when this request the following POST request is sent (note the added text in red) it does not work. A System.NullReferenceException is thrown because the 'request' variable never gets set.
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:acceptCharge xmlns:ns2="http://sample.ws.com/">
<request>
<RequestID>12648638354235</RequestID>
<ChargeAmount>$12.98</ChargeAmount>
<ChargeDate>2020-05-01T11:38:19.209Z</ChargeDate>
</request>
</ns2:acceptCharge>
</S:Body>
</S:Envelope>
In this case, I do not have control of the Client message structure, so I cannot simply remove the namespace/prefix to get the server to work like I did in the first example. Any thoughts on what is causing this? or how I can remedy it? (ASMX attached below)
namespace TestAPI
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://sample.ws.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[DataContract()]
public class DataInput
{
[DataMember]
public string RequestID { get; set; }
[DataMember]
public string ChargeAmount { get; set; }
[DataMember]
public string ChargeDate { get; set; }
}
[DataContract]
public class DataOutput
{
[DataMember]
public string RequestID { get; set; }
[DataMember]
public bool UpdateSuccessful { get; set; }
}
[SoapDocumentMethod(Action = "http://sample.ws.com/Endpoints/acceptChargeRequest", ResponseElementName = "acceptChargeResponse")]
[WebMethod(Description = "Operation to respond to Accept Charges")]
[return: XmlElement(ElementName = "response", Namespace = "")]
public DataOutput[] acceptCharge(DataInput request)
{
System.Diagnostics.Debug.WriteLine(request.ChargeAmount);
DataOutput[] vRes = new DataOutput[]
{
new DataOutput()
{
RequestID = request.RequestID,
UpdateSuccessful = true,
}
};
return vRes;
}
}
}