VS 2008、.net 3.5、WCF(環境:WindowsXPおよびVS2008)を使用して外部Webサービス(WebサービスにはPHPが実装されています)を利用しようとしています。Webサービスにサービス参照を追加すると、VSはWCFプロキシを生成します。
バインディングはbasicHttpBindingです。
プロキシを使用してWebサービスのメソッドを呼び出すと、ProtocolExceptionが発生し始め、次のエラーメッセージが表示されました。
System.ServiceModel.ProtocolException:コンテンツタイプtext / xml; 応答メッセージのcharset=ISO-8859-1が、バインディングのコンテンツタイプ(text / xml; charset = utf-8)と一致しません。カスタムエンコーダーを使用する場合は、IsContentTypeSupportedメソッドが正しく実装されていることを確認してください。
応答の最初の644バイトは次のとおりです。
これは成功しました
さて、私はiso-8859-1エンコーディングでサービスを呼び出す必要がありました。
それを解決するための有用なサンプルソースコードはありますか?
アップデート:
WCFで使用されるデフォルトのエンコーダーは、UTF-8およびUTF-16(ビッグエンディアンとリトルエンディアン)でのみ機能します。
app.configのバインディングでtextEncoding="iso-8859-1"を使用すると、
このエラーが発生します:
System.ArgumentException:Noseadmitelacodificacióndetexto'iso-8859-1'usada en el formato de mensajedetexto。Nombredelpará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(Binding binding)System.ServiceModel.Description.ConfigLoader.LookupBinding(String bindingSectionName、String configurationName、ContextInformation context)System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint、String configurationName)システム。 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()
アップデート:
WCFからISO-8859-1エンコーディングを使用するWebサービスを呼び出す
WCFからISO-8859-1エンコーディングを使用するWebサービスを呼び出す
このMSDNページ(http://msdn.microsoft.com/en-us/library/ms751486(v=VS.90).aspx)は、utf-8、utf-以上をサポートできる「CustomTextEncoder」を作成する方法を示しています。 16およびユニコードエンコーディング。完全なサンプルソースコードが含まれており、物事を進めるのに非常に役立ちました。
CustomTextMessageEncodingElementを使用していますが、エラーが発生します。
コンテンツタイプtext/xml; 応答メッセージのcharset=ISO-8859-1が、バインディングのコンテンツタイプ(text / xml; charset = iso-8859-1)と一致しません。カスタムエンコーダーを使用する場合は、IsContentTypeSupportedメソッドが正しく実装されていることを確認してください。応答の最初の1024バイトは次のとおりです。**
サンプルMSDNのコードから、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);
}
「{0};charset={1}」を「{0};charset= {1}」に置き換えます(空白を含めました)
次に、エラーが発生します。
送信メッセージのメッセージバージョン(Soap11(http://schemas.xmlsoap.org/soap/envelope/)AddressingNone
(http://schemas.microsoft.com/ws/2005/05/addressing/none))はしませんエンコーダのそれと一致します
(Soap12(http://www.w3.org/2003/05/soap-envelope)Addressing10(http://www.w3.org/2005/08/addressing))。
バインディングがメッセージと同じバージョンで構成されていることを確認してください。