WCF异常:短信编码和ISO-8859-1编码 [英] WCF Exception: Text Message Encoding and ISO-8859-1 Encoding

查看:772
本文介绍了WCF异常:短信编码和ISO-8859-1编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:结果
调用使用WCF从ISO-8859-1编码



web服务


我想消费外部Web服务使用VS 2008,.NET 3.5(Web服务有PHP实现),WCF(环境:Windows XP和VS 2008) 。我添加服务引用到Web服务,VS生成WCF代理。



绑定是basicHttpBinding的。



我打电话在Web服务方法,使用代理服务器,然后我开始一个的ProtocolException,我收到以下错误消息:




System.ServiceModel.ProtocolException:
中的内容类型text / xml的;
字符集=回应
消息ISO-8859-1不匹配绑定的内容
型(文/ XML;
的charset = UTF-8)。如果使用自定义的
编码器,可以肯定的是,
IsContentTypeSupported方法正确实现



第644个字节的响应分别为:



这是成功的。




好吧,我需要调用服务于ISO-8859-1编码。



为解决这个问题。



更新任何有用的示例源代码:



在WCF中使用的默认编码器只能使用UTF-8和UTF-16(大和little endian)。



如果我在app.config中结合使用textEncoding =ISO-8859-1



我得到这个错误:




System.ArgumentException:没有本身admite
LAcodificación德textoISO-8859-1
USADA恩报德formato德mensaje
texto 。农布雷德尔parámetro:编码



System.ServiceModel.Channels.TextEncoderDefaults.ValidateEncoding(编码
编码)
System.ServiceModel.Channels.TextMessageEncodingBindingElement。 set_WriteEncoding(编码
值)
System.ServiceModel.BasicHttpBinding.set_TextEncoding(编码
值)
System.ServiceModel.Configuration.BasicHttpBindingElement.OnApplyConfiguration(绑定
结合)
System.ServiceModel.Configuration.StandardBindingElement.ApplyConfiguration(绑定
结合)
System.ServiceModel.Description.ConfigLoader.LookupBinding(字符串
bindingSectionName,字符串
configurationName,ContextInformation
上下文)
System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(serviceEndpoint
serviceEndpoint,字符串
configurationName)
System.ServiceModel.ChannelFactory.ApplyConfiguration(字符串
configurationName)
System.ServiceModel.ChannelFactory.InitializeEndpoint(字符串
configurationName,的EndpointAddress
地址)构造函数(字符串
endpointConfigurationName,
的EndpointAddress remoteAddress)
CreateSimplexFactory( )
CreateChannelFactory()
CreateChannelFactoryRef(EndpointTrait`1
endpointTrait)
InitializeChannelFactoryRef()构造函数()
IntegracionEasyVista.ServiceEasyVista.WebServicePortTypeClient..ctor()




更新:



调用使用ISO- Web服务从WCF 8859-1编码



调用使用ISO-8859-1编码从WCF

web服务

这个MSDN页面(HTTP:/ /msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx)展示了如何创建一个CustomTextEncoder,它可以支持比UTF-8,UTF-16和Unicode编码等等。它包括完整的示例源代码,是我得到的东西去非常有用的。



我用CustomTextMessageEncodingElement,但我得到的错误:




内容类型text / xml的;字符集= ISO-8859-1响应报文不匹配绑定的内容类型(文本/ XML的,字符集= ISO-8859-1)。如果使用自定义的编码,确保IsContentTypeSupported方法正确实施。第一个1024字节的响应是:**




从样品代码MSDN,我从修改CustomTextMessageEncoder类的构造函数:

 公共CustomTextMessageEncoder(CustomTextMessageEncoderFactory工厂)
{
writerSettings =新XmlWriterSettings();
writerSettings.Encoding = Encoding.GetEncoding(factory.CharSet);
的contentType =的String.Format({0};字符集= {1},
factory.MediaType,this.writerSettings.Encoding.HeaderName);
}



我替换{0};字符集= {1}的{ 0};字符集= {1}(我已经包含了一个空白)



然后,我得到的错误:




传出消息(Soap11(http://schemas.xmlsoap.org/soap/envelope/)AddressingNone
的消息版本(http://schemas.microsoft.com / WS / 2005/05 /寻址/无))不匹配的编码器

(SOAP12(http://www.w3.org/2003/05/soap-envelope)Addressing10的( http://www.w3.org/2005/08/addressing))。
确保配置了相同的版本信息的绑定。



解决方案

这是否已有答案的帮助? 调用使用ISO-8859-1 web服务从WCF 编码


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

I am trying to consume an external Web Service (the web service has PHP implementation) using VS 2008, .net 3.5, WCF( Environment : Windows XP and VS 2008). I add Service Reference to Web Service, VS generates WCF Proxy.

Binding is basicHttpBinding.

I call to method in Web Service, using Proxy, then I started getting a ProtocolException, I received the following error message :

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

Well, I needed to call a service in iso-8859-1 encoding.

Any useful sample source code for solve it?

Update:

The default encoder used in WCF only works with UTF-8 and UTF-16 (big and little endian).

If I use textEncoding="iso-8859-1" in binding in app.config,

I get this error:

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

Update:

Calling a web service that uses ISO-8859-1 encoding from WCF

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

This MSDN page (http://msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx) shows how to create a "CustomTextEncoder" which can support more than utf-8, utf-16 and unicode encodings. It includes full sample source code and was very useful for me to get things going.

I use CustomTextMessageEncodingElement, but I get error:

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

From code of Samples MSDN, I modify the constructor from CustomTextMessageEncoder class:

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 replace "{0};charset={1}" by "{0}; charset={1}" (I have included an blank)

Then, I get the error:

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.

解决方案

Does this existing answer help? Calling a webservice that uses ISO-8859-1 encoding from WCF

这篇关于WCF异常:短信编码和ISO-8859-1编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆