我去徹底堅果和解決它在可能最壞的方式,但它確實幫助我完成我的任務,因爲設置的CultureInfo或設置requestencoding上的WebClient沒有幫助:自定義的SoapExtension :
Public Class MySoapExtension
Inherits SoapExtension
Private oldStream As Stream
Private newStream As Stream
Public Overrides Function ChainStream(stream As Stream) As Stream
oldStream = stream
newStream = New MemoryStream()
Return newStream
End Function
Public Overloads Overrides Function GetInitializer(methodInfo As _
LogicalMethodInfo, _
attribute As SoapExtensionAttribute) As Object
End Function
Public Overloads Overrides Function GetInitializer(WebServiceType As _
Type) As Object
End Function
Public Overrides Sub Initialize(initializer As Object)
End Sub
Public Overrides Sub ProcessMessage(message As SoapMessage)
Select Case message.Stage
Case SoapMessageStage.BeforeSerialize
Case SoapMessageStage.AfterSerialize
WriteOutput(message)
Case SoapMessageStage.BeforeDeserialize
WriteInput(message)
Case SoapMessageStage.AfterDeserialize
Case Else
Throw New Exception("invalid stage")
End Select
End Sub
' Write the SOAP message out to a file.
Public Sub WriteOutput(message As SoapMessage)
newStream.Position = 0
Copy(newStream, oldStream)
End Sub
' Write the SOAP message out to a file.
Public Sub WriteInput(message As SoapMessage)
Copy(oldStream, newStream)
newStream.Position = 0
End Sub
Sub Copy(fromStream As Stream, toStream As Stream)
Dim reader As New StreamReader(fromStream)
Dim writer As New StreamWriter(toStream)
writer.WriteLine(ReplaceInvalidChars(reader.ReadToEnd()))
writer.Flush()
End Sub
Private Function ReplaceInvalidChars(ByVal content As String) As String
If content.Contains("salesOrderInfo") Then
Return MagentoHackHelper.Encode(content)
Else
Return content
End If
End Function
End Class
Public Class MagentoHackHelper
Public Shared Function Encode(content As String) As String
content = content.Replace("Å", "##Aaring##")
content = content.Replace("Ä", "##Auml##")
content = content.Replace("Ö", "##Ouml##")
content = content.Replace("å", "##aaring##")
content = content.Replace("ä", "##auml##")
content = content.Replace("ö", "##ouml##")
Return content
End Function
Public Shared Function Decode(content As String) As String
content = content.Replace("##Aaring##", "Å")
content = content.Replace("##Auml##", "Ä")
content = content.Replace("##Ouml##", "Ö")
content = content.Replace("##aaring##", "Å")
content = content.Replace("##auml##", "Ä")
content = content.Replace("##ouml##", "Ö")
Return content
End Function
End Class
我不認爲有很多人知道Magento。如果可以的話 - 將發佈加載這些響應的代碼是很好的。 – outcoldman 2012-08-13 14:57:22
這不是Magento的錯(無論Magento是什麼),但客戶端代碼不能正確解釋響應。 – 2012-08-13 15:00:04
我從來沒有說過它是Magentos的錯,我在問我如何強制我的客戶端正確解釋響應。 – 2012-08-14 10:46:08