2010-11-08 26 views
5

Possible Duplicate:
Calling a webservice that uses ISO-8859-1 encoding from WCFWCF Ngoại lệ: Text Message Encoding và Encoding ISO-8859-1

Tôi cố gắng để tiêu thụ một dịch vụ Web bên ngoài (các dịch vụ web có thực hiện PHP) sử dụng VS 2008, .net 3.5, WCF (Môi trường: Windows XP và VS 2008). Tôi thêm Service Reference to Web Service, VS tạo ra WCF Proxy.

Ràng buộc là cơ bảnHttpBinding.

tôi gọi đến phương pháp trong Web Service, sử dụng Proxy, sau đó tôi bắt đầu nhận được một ProtocolException, tôi nhận được thông báo lỗi sau:

System.ServiceModel.ProtocolException: The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.

The first 644 bytes of the response were:

This was successful

Vâng, tôi cần phải gọi một dịch vụ trong iso-8859-1 mã hóa.

Bất kỳ mã nguồn mẫu hữu ích nào để giải quyết?

Cập nhật:

Các bộ mã hóa mặc định được sử dụng trong WCF chỉ làm việc với UTF-8 và UTF-16 (lớn và little endian).

Nếu tôi sử dụng textEncoding = "iso-8859-1" trong ràng buộc trong app.config,

tôi nhận được lỗi này:

System.ArgumentException: No se admite la codificación de texto 'iso-8859-1' usada en el formato de mensaje de texto. Nombre del parámetro: encoding.

System.ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding(Encoding encoding) System.ServiceModel.Channels.TextMessageEncodingBindingElement.set_WriteEncoding(Encoding value) System.ServiceModel.BasicHttpBinding.set_TextEncoding(Encoding value) System.ServiceModel.Configuration.BasicHttpBindingElement.OnApplyConfiguration(Binding binding) System.ServiceModel.Configuration.StandardBindingElement.ApplyConfiguration(Binding binding) System.ServiceModel.Description.ConfigLoader.LookupBinding(String bindingSectionName, String configurationName, ContextInformation context) System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) ctor(String endpointConfigurationName, EndpointAddress remoteAddress) CreateSimplexFactory() CreateChannelFactory() CreateChannelFactoryRef(EndpointTrait`1 endpointTrait) InitializeChannelFactoryRef() ctor() IntegracionEasyVista.ServiceEasyVista.WebServicePortTypeClient..ctor() in

Cập nhật:

Gọi một dịch vụ web mà sử dụng mã hóa ISO-8859-1 từ WCF

Calling a webservice that uses ISO-8859-1 encoding from WCF

Trang MSDN này (http://msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx) cho thấy cách tạo "CustomTextEncoder" có thể hỗ trợ nhiều hơn utf-8, utf-16 và mã hóa unicode. Nó bao gồm mã nguồn mẫu đầy đủ và rất hữu ích cho tôi để có được những thứ đang diễn ra.

tôi sử dụng CustomTextMessageEncodingElement, nhưng tôi nhận được lỗi:

The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml;charset=iso-8859-1). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:**

Từ mã của mẫu MSDN, tôi sửa đổi các nhà xây dựng từ lớp CustomTextMessageEncoder:

public CustomTextMessageEncoder(CustomTextMessageEncoderFactory factory) 
{ 
    writerSettings = new XmlWriterSettings(); 
    writerSettings.Encoding = Encoding.GetEncoding(factory.CharSet); 
    contentType = string.Format("{0};charset={1}", 
    factory.MediaType, this.writerSettings.Encoding.HeaderName); 
} 

tôi thay thế "{0}; charset = {1} "bởi" {0}; charset = {1} "(Tôi đã bao gồm một ô trống)

Sau đó, tôi gặp lỗi:

The message version of the outgoing message (Soap11 (http://schemas.xmlsoap.org/soap/envelope/) AddressingNone
(http://schemas.microsoft.com/ws/2005/05/addressing/none)) does not match that of the encoder

(Soap12 (http://www.w3.org/2003/05/soap-envelope) Addressing10 (http://www.w3.org/2005/08/addressing)).
Make sure the binding is configured with the same version as the message.

Trả lời

-3

Tôi nghĩ bạn có thể làm việc này bằng cách thay đổi cấu hình ràng buộc của bạn một cách rõ ràng để đặt thuộc tính textEncoding thành "iso-8859-1" thay vì giá trị mặc định là "utf-8".

+2

Không cho tôi, trong TextEncoderDefaults.ValidateEncoding (Mã hóa mã hóa). System.ArgumentException: Không hỗ trợ mã hóa văn bản 'iso-8859-1' – Kiquenet

+0

Bạn nói đúng; Tôi đã không thử nghiệm nó trước đây. Có khả năng một số hạn chế ngu ngốc trong WCF. – tomasr

+2

Có thể xóa câu trả lời này tốt hơn. – Kiquenet