Question

I have seen lots of examples regarding WShttpbinding and Silverlight. Also, I successfully managed to run the application but I have to create custom binding from code behind.

I have tried that out but am getting an Error as below:

In Binding 'MyCustom', TransportBindingElement 'HttpsTransportBindingElement' does not
appear last in the BindingElementCollection.  Please change the order of elements such
that the TransportBindingElement is last.

Code

public static MyTempService.ServiceClient WCFServiceClient()
{
    {       
        EndpointAddressBuilder AddressBuilder = new EndpointAddressBuilder(new EndpointAddress("https://node94.MyWab.local:8089/WcfService/Service.svc"));      

        CustomBinding Cusbinding = new CustomBinding
        ("MyCustom",
         "MyTempService",
         SecurityBindingElement.CreateUserNameOverTransportBindingElement(),
         new BinaryMessageEncodingBindingElement(),
         new HttpsTransportBindingElement()
        );

        Cusbinding.Elements.Add(new TextMessageEncodingBindingElement()
        {
            MessageVersion = System.ServiceModel.Channels.MessageVersion.Default,
            WriteEncoding = System.Text.Encoding.UTF8
        });

        Cusbinding.OpenTimeout = new TimeSpan(0, 5, 0);
        Cusbinding.CloseTimeout = new TimeSpan(0, 5, 0);
        Cusbinding.ReceiveTimeout = new TimeSpan(0, 5, 0);
        Cusbinding.SendTimeout = new TimeSpan(0, 5, 0);

        return new MyTempService.ServiceClient(Cusbinding, AddressBuilder.ToEndpointAddress());
    }
}

Service Config File

<system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
      <endToEndTracing propagateActivity="true" activityTracing="true"
        messageFlowTracing="true" />
    </diagnostics>

    <behaviors>
      <serviceBehaviors>
        <behavior name="WsBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>

          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"/>
          </serviceCredentials>

        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <wsHttpBinding>
        <binding name="WsBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" negotiateServiceCredential="false"
              algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="WsBehaviour" name="Service">
        <endpoint address="https://node94.MyWeb.local:8089/WcfService/Service.svc"
          binding="wsHttpBinding" bindingConfiguration="WsBinding" contract="IService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

No correct solution

OTHER TIPS

when I look at your code, I see the last in BindingElementCollection is

TextMessageEncodingBindingElement()

try it on the following way:

1) remove the new HttpsTransportBindingElement() from the construtor

2) add this element as the last element after

    Cusbinding.Elements.Add(new TextMessageEncodingBindingElement()
    {
        MessageVersion = System.ServiceModel.Channels.MessageVersion.Default,
        WriteEncoding = System.Text.Encoding.UTF8
    });

    Cusbinding.Elements.Add(new HttpsTransportBindingElement());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top