Reputation: 97
Below is the webmethod in asmx that get the request xml
<WebMethod>
Public Function SubmitOrder(SubmitOrderRequest As SubmitOrderRequest) As SubmitOrderResponse Implements IIHybrisOrderImportServiceSoapBinding.SubmitOrder
Dim inputserilize As New XmlSerializer(SubmitOrderRequest.GetType)
Dim strwriters = New StringWriter
inputserilize.Serialize(strwriters, SubmitOrderRequest)
WriteToFile("Input XML: " & strwriters.ToString & vbCrLf)
The XML request is as below:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ns2:SubmitOrderRequest xmlns:ns2="http://cos.ws.sideup.reply.eu/SubmitOrderRequest">
<Orders>
<Order>
<Action>CREATE</Action>
<BillingAddress>
<BillingAddress1>Paulñ Pogbaà</BillingAddress1>
I am expecting the above XML to be displayed by the asmx with the BillingAddress1 value as seen above but what i get is as seen below:
<?xml version="1.0" encoding="iso-8859-1"?>
<SubmitOrderRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Orders>
<Order>
<Action>CREATE</Action>
<BillingAddress>
<BillingAddress1>Paul?? Pogba??</BillingAddress1>
How can i get the those special characters to be displayed properly?
Upvotes: 0
Views: 296
Reputation: 3424
If you notice the encoding got changed from UTF-8
to iso-8859-1
You need to set the encoding in the StringWriter
, unfortunately it doesn't support setting encoding straight-forwardly. So create your own StringWriter
by inheriting from StringWriter
.
Public Class MyStringWriter
Inherits StringWriter
Public Overrides Property Encoding As Encoding
Get
Return Encoding.UTF8
End Get
End Property
End Class
Then use in your code:
Dim inputserilize As New XmlSerializer(SubmitOrderRequest.GetType)
Dim strwriters = New MyStringWriter
inputserilize.Serialize(strwriters, SubmitOrderRequest)
WriteToFile("Input XML: " & strwriters.ToString & vbCrLf)
Dim inputserilize As New XmlSerializer(SubmitOrderRequest.GetType)
Dim strwriters = New StringWriter
inputserilize.Serialize(strwriters, SubmitOrderRequest)
WriteToFile("Input XML: " & strwriters.ToString & vbCrLf)
Upvotes: 1