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

问题描述

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 :

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:

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:

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:

解决方案

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

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

08-18 22:38