none
WFS Bindings. Problem to use customBinding instead of wsHttpBinding to manage encoding ISO-8859-1 RRS feed

  • Question

  • Hello,

    I have a web service which receives and process Message. (in WFS format but it's not the main part).

    All works in UTF-8 but i have to make my service elvole to manage encoding ISO-8859-1.

    Based on my research i try to use customBinding instead of wsHttpBinding but i can't succed to first have the same behavior with utf-8 Message.

     This is the original set up:

    global.asax:

    private void RegisterRoutes()
        {
            WebServiceHostFactory factory = new WebServiceHostFactory();
    
            RouteTable.Routes.Add(new ServiceRoute("", factory, typeof(UserServices)));
            logger.Info("base REST route registered");
        }

    Web.config

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <bindings>
          <wsHttpBinding>
            <binding name="SecureBinding">
              <security mode="Message">
                <message clientCredentialType="UserName" />
              </security>
            </binding>
            <binding name="UnsecureBinding" />
          </wsHttpBinding>
        </bindings>
       </system.serviceModel>

    And my InterfaceIUserServices

    public interface IUserServices
    {
        [OperationContract]
        Message WFSService(Message incomingMessage);
    
        [OperationContract]
        Stream WCSService(string serviceName, string serviceVersion, string coverageType, string crs, string imageFormat, string featureid, string BBox, string response_crs);
        
        [OperationContract]
        Message WCSCapabilities(string serviceName, string serviceVersion);
    }

    If you need more details on those set up just ask.

    This his how i try to use customBinding in the Web.Config:

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <services>
          <service
              name="UserServices"
              >
            <endpoint address=""
                     binding="customBinding"
                     bindingConfiguration="ISO88591Binding"
                     contract="IUserServices" />
            <endpoint address="unsecure"
                     binding="customBinding"
                     bindingConfiguration="UnsecureBinding"
                     contract="IUserServices" />
          </service>
        </services>
        <extensions>
          <bindingElementExtensions>
            <add name="customTextMessageEncoding"
                 type="Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement, 
                       Microsoft.ServiceModel.Samples.CustomTextEncoder"/>
          </bindingElementExtensions>
        </extensions>
        <bindings>
          <customBinding>
            <binding name="ISO88591Binding">
              <transactionFlow />
              <security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
                <secureConversationBootstrap messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
              </security>
              <textMessageEncoding />
              <httpTransport />
            </binding>
            <binding name="UnsecureBinding"><httpTransport/></binding>
          </customBinding>
        </bindings>
      </system.serviceModel>

    To translate my binding i use this WCF Binding converter:

    http://webservices20.cloudapp.net/

    When i run my application i first have an error with WCSCapabilities:

    The operation 'WCSCapabilities' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

    I found that this is due to the way i declare the method so i just first bypass this problem and comment the method.

    Then when i run my service i'm not able to enter WFSService() when i send a Message on my service.

    I try to understand what is wrong and how can i use customBinding properly. So if you have any advices or if you already used such a service thanks for your help.

    Best regards,

    Christophe.


    Tuesday, November 3, 2015 9:04 AM

Answers

  • Hi lavoye Christophe,

    Maybe you can try test the service with WCF Test Client.

    go to the following location:

    C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\

    Best Regards,

    Grady

    Friday, November 6, 2015 7:49 AM
    Moderator

All replies

  • Hi lavoye Christophe,

    May be you can try set the customTextMessageEncoding as ISO-8859-1 in your web.config file.

    Like below:

    bindings>
          <customBinding>
            <binding name="ISO8859Binding" >
              <customTextMessageEncoding encoding="ISO-8859-1" />
              <httpTransport />
            </binding>
          </customBinding>
        </bindings>
    

    For more information, please refer to the following articles:

    1.Custom Message Encoder: Custom Text Encoder

    2.WCF Extensibility – Message Encoders

    Best Regards,

    Grady

    Wednesday, November 4, 2015 6:44 AM
    Moderator
  • Hi Tracy,

    When i've tried to do this i get the warning that "customTextMessageEncoding" is an invalid child element for "binding".

    And when i run i get this error:


    Do I miss a step to declare or refer custom classes?

    As i'm stuck, at the same time i try to configure my service by the code. So i load custom classes on my project and then i try to override CreateHostService()

    https://msdn.microsoft.com/en-us/library/ms751486.aspx

    http://www.codeproject.com/Tips/29167/A-Custom-ServiceHostFactory

    In global.asax

    i declare:

            WCFUtil.WCFServiceHostFactory factory = new WCFUtil.WCFServiceHostFactory();
            RouteTable.Routes.Add(new ServiceRoute("", factory, typeof(UserServices)));

    WCFServiceHostFactory is my own class inheriting from WebSercieHostFactory..

    namespace WCFUtil
    {
        /// <summary>
        /// Classe pour surcharger WebServiceHostFactory et ajouter customBinding pour ISO-8859-1 par le code
        /// </summary>
        public class WCFServiceHostFactory : WebServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            {
                ServiceHost host = new ServiceHost(serviceType, baseAddresses);
    
                foreach (Uri baseAddress in baseAddresses)
                {
                    WSHttpBinding binding = CreateRestBinding(baseAddress);
                    ServiceEndpoint endpoint = host.AddServiceEndpoint(serviceType.GetInterfaces()[0], binding, baseAddress);
                }
                return host;
            }
    
    
            private WSHttpBinding CreateRestBinding(Uri baseAddress)
            {
                WSHttpBinding binding;
                if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    binding = new WSHttpBinding(SecurityMode.Message);
                    binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
                }
                else
                {
                    binding = new WSHttpBinding();
                }
               
    
                return binding;
            }
        }
    }

    by this way i get the error

    I'm still working on it...

    Thanks for your time,

    Best regards,

    Christophe.



    Wednesday, November 4, 2015 10:34 AM
  • I Suceed to use my customTextMessageEncoding with thos config:

        <bindings>
          <customBinding>
            <binding name="ISO8859Binding" >
              <transactionFlow />
              <security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
                <secureConversationBootstrap messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
              </security>
              <customTextMessageEncoding encoding="ISO-8859-1" />
              <httpTransport />
            </binding>
          </customBinding>
        </bindings>
    
    ...
    
        <extensions>
          <bindingElementExtensions>
            <add name="customTextMessageEncoding"
                 type="Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement, 
                      CustomTextEncoder"/>
          </bindingElementExtensions>
        </extensions>


    My service is still working for message such as:

    <?xml version="1.0" encoding="utf-8"?>
    <wfs:GetFeature ...

    But still not "catching"

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <wfs:GetFeature

     To test my service i'm using SoapUI. Is the way i'm testing wrong?

    King regards,

    Christophe.

    Wednesday, November 4, 2015 2:15 PM
  • Hi lavoye Christophe,

    Maybe you can try test the service with WCF Test Client.

    go to the following location:

    C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\

    Best Regards,

    Grady

    Friday, November 6, 2015 7:49 AM
    Moderator