简体   繁体   English

更改WCF响应编码

[英]Change WCF Response encoding

I have a WCF service who must now send data in this encoding : iso-8859-1. 我有一个WCF服务,该服务现在必须以以下编码发送数据:iso-8859-1。

I tried to change IIS configguration or add globalization balise in the config but the response of the service is always on UTF-8. 我试图更改IIS配置或在配置中添加全球化平衡,但是该服务的响应始终在UTF-8上。

Can somebody help me ? 有人可以帮我吗?

Thanks. 谢谢。

You can't do this out of the box in WCF. 您不能在WCF中直接使用此功能。 See this answer for some details on how to create a custom binding that will support ISO-8859-1: https://stackoverflow.com/a/1908154/2420979 有关如何创建将支持ISO-8859-1的自定义绑定的一些详细信息,请参见以下答案: https : //stackoverflow.com/a/1908154/2420979

I downloaded the CustomTextMessageEncoder for the framework 4.0, i succeeded to display the svc page but all my calls returns nothing and the HELP balise don't display for the rest service. 我为框架4.0下载了CustomTextMessageEncoder,我成功显示了svc页面,但我的所有调用均未返回任何内容,其余服务未显示HELP应答窗口。

I noticed also that when i call my local service it executes the method twice without final result but if i change the binding into a webHttpBinding i execute the method one time and it works 我还注意到,当我调用本地服务时,它两次执行该方法而没有最终结果,但是如果我将绑定更改为一个webHttpBinding,则我将执行一次该方法并且它可以工作

Here is my config : 这是我的配置:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="TestTheIso.Service1" behaviorConfiguration="ServiceBehaviour">
        <endpoint  binding="customBinding" bindingConfiguration="DefaultBinding"   contract="TestTheIso.IService1" behaviorConfiguration="toto">
        </endpoint>
      </service>
    </services>
    <bindings>
      <customBinding>
        <binding name="DefaultBinding">
          <customTextMessageEncoding encoding="ISO-8859-1" messageVersion="None" />
          <httpTransport manualAddressing="true"/>
        </binding>
      </customBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="toto">
          <webHttp helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <extensions>
      <bindingElementExtensions>
        <add name="customTextMessageEncoding"
             type="Microsoft.Samples.CustomTextMessageEncoder.CustomTextMessageEncodingElement, CustomTextMessageEncoder"/>
      </bindingElementExtensions>
    </extensions>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM