HttpClient Soap Returned XML Result with back slash. How to removed the back slash \

Micheale

New member
Joined
Aug 19, 2022
Messages
1
Programming Experience
10+
Hi All,

I have below code:

HttpClient Soap Returned XML Result with back slash. How to removed the back slash \:
string urlstr = ConfigurationManager.AppSettings["FNOEntitlementOrderServURL"];
                    string authstr = ConfigurationManager.AppSettings["auth"];

                    HttpClient client = new HttpClient();

                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));

                    client.DefaultRequestHeaders.Add("Authorization", authstr);
                    client.DefaultRequestHeaders.Add("SOAPAction", "");
                    string bodystr = @"<Envelope xmlns=""http://schemas.xmlsoap.org/soap/envelope/"">
                                    <Body>
                                    <searchEntitlementRequest xmlns=""urn:v5.webservices.operations.flexnet.com"">
                                        <entitlementSearchCriteria>
                                        </entitlementSearchCriteria>
                                        <batchSize>50</batchSize></searchEntitlementRequest></Body></Envelope>";


                    var stringContent = new StringContent(bodystr, System.Text.UnicodeEncoding.UTF8, "text/xml");

                    HttpResponseMessage response = client.PostAsync(urlstr, stringContent).Result;
                    response.EnsureSuccessStatusCode();

                    if (response.IsSuccessStatusCode)
                    {
                        HttpContent content = response.Content;
                        string str = await content.ReadAsStringAsync();

                        try
                        {
                            InsertToDB(str, batchid.ToString(), "[dbo].[FNO_EntitlementInsertRecord]");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("{0} ({1})", ex.InnerException, bodystr);

                        }

                    }
                    else
                    {
                        Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                    }

Please advise how to removed the back slash? When I write out the result for str. It's showing something like this:-

"<?xml version=\"1.0\" encoding=\"utf-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><searchEntitlementResponse xmlns=\"urn:v5.webservices.operations.flexnet.com\"><statusInfo><status>SUCCESS</status></statusInfo><entitlement><simpleEntitlement>...</simpleEntitlement></entitlement></searchEntitlementResponse></soapenv:Body></soapenv:Envelope>"

I want the result to be:

"<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><searchEntitlementResponse xmlns="urn:v5.webservices.operations.flexnet.com"><statusInfo><status>SUCCESS</status></statusInfo><entitlement><simpleEntitlement>...</simpleEntitlement></entitlement></searchEntitlementResponse></soapenv:Body></soapenv:Envelope>"

Please advise.

Regards,
Micheale
 
Last edited:
I don't think there's a problem here at all. Try writing this in the code window:
C#:
var text = "<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><searchEntitlementResponse xmlns="urn:v5.webservices.operations.flexnet.com"><statusInfo><status>SUCCESS</status></statusInfo><entitlement><simpleEntitlement>...</simpleEntitlement></entitlement></searchEntitlementResponse></soapenv:Body></soapenv:Envelope>";
What happens? Now try writing this in the code window:
C#:
var text = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><searchEntitlementResponse xmlns=\"urn:v5.webservices.operations.flexnet.com\"><statusInfo><status>SUCCESS</status></statusInfo><entitlement><simpleEntitlement>...</simpleEntitlement></entitlement></searchEntitlementResponse></soapenv:Body></soapenv:Envelope>";
What happens? Add this:
C#:
Console.WriteLine(text);
What do you see?
 

Latest posts

Back
Top Bottom