System.ServiceModel core wcf client bindings

381 views Asked by At

I'm using .NET Core 6 and have the 6.0 Nuget packages for System.ServiceModel which is this opensource code: https://github.com/dotnet/wcf

I'm trying to replicate client bindings from a .NET framework 4.6 project. Would someone be able to tell me if these bindings are supported?

<system.serviceModel>
    <bindings>
      <wsFederationHttpBinding>
        <binding name="wsFederationHttpBindingConfiguration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="1638400" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="TransportWithMessageCredential">
            <message algorithmSuite="Default" issuedKeyType="SymmetricKey" issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" negotiateServiceCredential="true">
              <issuer address="...SecurityTokenService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration">
                <headers>
                  <ServiceContractType xmlns="http://schemas.test/Contracts">ServiceContracts.ISecurityTokenService</ServiceContractType>
                </headers>
              </issuer>
              <issuerMetadata address="...SecurityTokenService.svc/mex" />
            </message>
          </security>
        </binding>
      </wsFederationHttpBinding>

      <wsHttpBinding>
        <binding name="wsHttpBindingConfiguration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <client>
      <endpoint address="...location.svc" binding="wsFederationHttpBinding" bindingConfiguration="wsFederationHttpBindingConfiguration" contract="ILocationService" name="LocationServiceEndpoint" />
      <endpoint address="...admin.svc" binding="wsFederationHttpBinding" bindingConfiguration="wsFederationHttpBindingConfiguration" contract="ServiceRef.IAdminService" name="AdminEndpoint">
        <headers>
          <ServiceContractType xmlns="http://schemas.test.Contracts">AdminService.Contracts.IAdminService</ServiceContractType>
        </headers>
      </endpoint>
   </client>
</system.serviceModel>

edit. my second sts call is failing with a 500. when diffing with a working legacy client, the largest difference is my core client missing:

    <t:EncryptWith>http://www.w3.org/2001/04/xmlenc#aes256-cbc</t:EncryptWith>
    <t:SignWith>http://www.w3.org/2000/09/xmldsig#hmac-sha1</t:SignWith>
    <t:CanonicalizationAlgorithm>http://www.w3.org/2001/10/xml-exc-c14n#</t:CanonicalizationAlgorithm>
    <t:EncryptionAlgorithm>http://www.w3.org/2001/04/xmlenc#aes256-cbc</t:EncryptionAlgorithm>

//currently how i'm setting up the binding:

    private void OpenClient()
    {
        var AdminServiceEndpointString = "blah.adminsvc.svc"
        EndpointAddress AdminServiceEndpointAddress = new EndpointAddress(AdminServiceEndpointString);

        AdminServiceClient client = new AdminServiceClient(GetBinding(), AdminServiceEndpointAddress);
        client.ClientCredentials.UserName.UserName = Utilities.GetUserName(DbInstanceId);
        client.ClientCredentials.UserName.Password = Utilities.GetUserPwd();
        client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
        {
            CertificateValidationMode = X509CertificateValidationMode.None,
            RevocationMode = X509RevocationMode.NoCheck,
        };

        Client = client;
    }

    private static Binding GetBinding()
    {
        var issuerBinding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential)
        {
            CloseTimeout = TimeSpan.FromMinutes(1),
            OpenTimeout = TimeSpan.FromMinutes(1),
            ReceiveTimeout = TimeSpan.FromMinutes(10),
            SendTimeout = TimeSpan.FromMinutes(11),
            BypassProxyOnLocal = false,
            TransactionFlow = false,
            MaxBufferPoolSize = 524288,
            MaxReceivedMessageSize = 6553600,
            MessageEncoding = WSMessageEncoding.Text,
            TextEncoding = System.Text.Encoding.UTF8,
            UseDefaultWebProxy = true,
           
        };
        issuerBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
        issuerBinding.Security.Message.EstablishSecurityContext = true;
        issuerBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;

        var endpointAddress = new EndpointAddress("https://blah.SecurityTokenService.svc");

        var tokenParameters = WSTrustTokenParameters.CreateWS2007FederationTokenParameters(issuerBinding, endpointAddress);
        tokenParameters.TokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1"; //"http://schemas.xmlsoap.org/ws/2005/02/sc/sct";
        tokenParameters.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11;
        tokenParameters.KeyType = System.IdentityModel.Tokens.SecurityKeyType.SymmetricKey;

        return new WSFederationHttpBinding(tokenParameters);
    }
1

There are 1 answers

1
Jiayao On

As far as I know, WSHttpBinding and WSFederationHttpBinding are already supported in Core. This project include an example of creating the binding.

Besides, the difference between.NET framework WCF and.NET core WCF scenarios is that the binding of the latter can only be configured in code, not in app.config.

You can refer to the following article to explain these application scenarios in detail :

CoreWCF 1.0 has been Released, WCF for .NET Core and .NET 5+

WSFederationHttpBinding in .NET Standard

Hope it helps.