2010-11-08 43 views
5

Possible Duplicate:
Calling a webservice that uses ISO-8859-1 encoding from WCFWCF İstisna: Kısa Mesaj Kodlama ve ISO-8859-1 Kodlama Ben harici Web Service tüketmek çalışıyorum

VS 2008, .net 3.5, WCF (Çevre kullanarak (web hizmeti PHP uygulaması vardır): Windows XP ve VS 2008). Web Hizmetine Hizmet Referansı ekliyorum, VS WCF Proxy'yi üretir.

Bağlama basicHttpBinding'dir.

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

Eh, iso-8859-1 bir hizmeti çağırmak için gerekli: Proxy kullanarak ben Web Hizmeti yöntemine çağrı

, o zaman bir ProtocolException başlarken, aşağıdaki hata iletisi aldım kodlaması.

Çözmek için herhangi bir kullanışlı örnek kaynak kodu?

Güncelleme: WCF kullanılan

geçerli kodlayıcı sadece UTF-8 ve UTF-16 (büyük ve küçük endian) ile çalışır.

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

Güncelleme:

ben app.config bağlanmada textEncoding = "iso-8859-1" kullanırsanız,

bu hatayı alıyorum bir web hizmeti çağırma

o WCF'nin

ISO-8859-1 kodlamasını kullanan

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

Bu MSDN sayfası (http://msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx), utf-8, utf-16 ve unicode kodlamalardan daha fazlasını destekleyebilen bir "CustomTextEncoder" yaratmayı gösterir. Tam örnek kaynak kodu içerir ve işlerimi almak için benim için çok yararlı oldu.

I CustomTextMessageEncodingElement kullanmak, ama elde hata MSDN, I CustomTextMessageEncoder sınıfından kurucu değiştirme Örneklerinde kodundan

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:**

:

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); 
} 

I yerine "{0}, karakter kümesi =

: {1}" ile "{0} karakter kümesi {1}" O

(bir boş dahil) genel =, hata olsun

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.

cevap

-3

Bu bağlamda, " textEncoding özelliğini "iso-8859-1" olarak ayarlamak için bağlama yapılandırmanızı açıkça değiştirerek çalışabilirsiniz.

+2

TextEncoderDefaults.ValidateEncoding içinde kodlama (Kodlama kodlaması). System.ArgumentException: Textencoding'i desteklemiyor 'iso-8859-1' – Kiquenet

+0

Haklısınız; Daha önce test etmemiştim. WCF'de aptalca bir sınırlama var. – tomasr

+2

Belki bu cevabı daha iyi silin. – Kiquenet