Fedex tracking API using .NET Core API – throwing 500 Error

I am writing logic to make Fedex API call in my .NET API Core application.
I got C#.NET sample code from Fedex Developer documentation.
I have all required data like Key, Password, AccountNumber, MeterNumber.

In the sample C#.NET console application(provided by Fedex on their developer guide site), they have added WSDL reference and TrackRequest, TrackService and TrackReply are available and Also SecurityProtocol TLS Settings are taken care.
we are able to call TrackService.Track method and successful test it.

Now my objective is to write this in .NET Core API project.

In Core API, i tried to add Service Reference to the WSDL (TrackServiceDefinitions.wsdl) file that is downloaded from Fedex documentation. That threw some nSwag related error, which i am not sure.

I am not sure how to build SOAP Request. This is how Fedex Tracking SOAPrequest looks like:
How to get full tracking info (Fedex Webservices)?

So i wrote the API Method as below.
I am getting 500 Internal Server Error.

What am i doing wrong here? Is there any other better/easy way to make this API Call?

Appreciate your responses.

        public IActionResult GetFedexTrackStatus(int trackingNumber)
            var sXml = @"<TrackRequest xmlns=''><WebAuthenticationDetail><UserCredential><Key>{Key}</Key>
        <TransactionDetail><CustomerTransactionId>Track By Number_v16</CustomerTransactionId></TransactionDetail>

            string Err = "";
            WebResponse WebRes = null;
            string sResponse = "";
                string URL = ""; 
                byte[] buffer = Encoding.UTF8.GetBytes(sXml);
                WebRequest WebReq = WebRequest.Create(URL);
                WebReq.Method = "POST";
                WebReq.Timeout = 1000000;
                WebReq.ContentType = "application/x-www-form-urlencoded";
                WebReq.ContentLength = buffer.Length;
                Stream ReqStream = WebReq.GetRequestStream();
                ReqStream.Write(buffer, 0, buffer.Length);
                WebRes = WebReq.GetResponse();
                Stream ResStream = WebRes.GetResponseStream();
                StreamReader ResReader = new StreamReader(ResStream);
                sResponse = ResReader.ReadToEnd();
            catch (Exception ex)
                Err = ex.Message.ToString();

            return Ok(sResponse);


edited 1 hour ago

asked 2 hours ago

333 bronze badges

Latest posts