none
How to set a configuration in code RRS feed

  • Question

  • Hello,  I have a old binding in my config file as follows:

    <basicHttpBinding>
            <binding name="SSORouterSOAP" closeTimeout="00:01:00" openTimeout="00:01:00"
              receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
              bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
              messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="Transport">
                <transport clientCredentialType="None" proxyCredentialType="None"
                  realm="" />
                <message clientCredentialType="Certificate" algorithmSuite="Default" />
              </security>
            </binding>

    </basicHttpBinding>

    I am trying to do that in code as such:

    BasicHttpBinding b = new BasicHttpBinding();
    b.MaxReceivedMessageSize = 2147483647;
    b.Security.Mode = BasicHttpSecurityMode.Transport;
    b.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;

    EndpointAddress e = new EndpointAddress("https://myendpoint.com/enrollment/");
    MyClient client = new MyClient(b, e);
    client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindBySerialNumber, "4C240403");

    No matter what I do, I get one of two errors:

    1) The HTTP request was forbidden with client authentication scheme 'Anonymous'

    or 

    2) The provided URI scheme https is invalid; expected http.

    My url is a secure one https://myendpoint.com/enrollment/

    Any help would be appreciated.


    Friday, November 7, 2014 10:58 PM

Answers

  • Hi Hiline1961,

    >>The HTTP request was forbidden with client authentication scheme 'Anonymous'

    As @SimonTaylor said, please try to use the TransportWithMessageCredential security mode in both the client and service side. Then please try to make sure that you have configurated the service certificate very well.

    >>The provided URI scheme https is invalid; expected http.

    Please try to make sure that you have used the following in your service config file which will allow both http and https:

    <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
    Or please try to add the following mex endpoint:
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />

    Best Regards,
    Amy Peng





    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, November 10, 2014 9:37 AM
    Moderator

All replies

  • You need to use BasicHttpSecurityMode.TransportWithMessageCredential.
    Saturday, November 8, 2014 1:32 AM
  • Hi Hiline1961,

    >>The HTTP request was forbidden with client authentication scheme 'Anonymous'

    As @SimonTaylor said, please try to use the TransportWithMessageCredential security mode in both the client and service side. Then please try to make sure that you have configurated the service certificate very well.

    >>The provided URI scheme https is invalid; expected http.

    Please try to make sure that you have used the following in your service config file which will allow both http and https:

    <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
    Or please try to add the following mex endpoint:
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />

    Best Regards,
    Amy Peng





    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, November 10, 2014 9:37 AM
    Moderator