SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a workflow custom action that uses a wcf webservice. The thing is, I have no proper way to attach the app.config file so I'd have to generate the bindings and the client endpoints manually from code.

Here's what I'm talking about:

            <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
        <endpoint address="http://localhost:55693/Service1.svc" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
                <dns value="localhost" />

How to do that? Would anyone give me any hints?

share|improve this question
up vote 1 down vote accepted

Though not an exact answer but you can get a head on your approach by the following example available on MSDN , using the WSHTTPBinding programatecally.

              public sealed class CustomBindingCreator

        public static void snippetSecurity()
            WSHttpBinding wsHttpBinding = new WSHttpBinding();
            WSHttpSecurity whSecurity = wsHttpBinding.Security;

        public static void snippetCreateBindingElements()
            WSHttpBinding wsHttpBinding = new WSHttpBinding();
            BindingElementCollection beCollection = wsHttpBinding.CreateBindingElements();

        private void snippetCreateMessageSecurity()
            WSHttpBinding wsHttpBinding = new WSHttpBinding();
            // SecurityBindingElement sbe = wsHttpBinding

        public static void snippetGetTransport()
            WSHttpBinding wsHttpBinding = new WSHttpBinding();
            //      TransportBindingElement tbElement = wsHttpBinding.GetTransport();

        public static void snippetAllowCookies()
            WSHttpBinding wsHttpBinding = new WSHttpBinding();
            wsHttpBinding.AllowCookies = true;

        public static Binding GetBinding()
            // securityMode is Message 
            // reliableSessionEnabled is true
            WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message, true);
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

            WSHttpSecurity security = binding.Security;
            return binding;


        public static Binding GetBinding2()

            // The security mode is set to Message.
            WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message);
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
            return binding;


        // This method creates a WSFederationHttpBinding. 
        public static WSFederationHttpBinding CreateWSFederationHttpBinding()
            // Create an instance of the WSFederationHttpBinding
            WSFederationHttpBinding b = new WSFederationHttpBinding();

            // Set the security mode to Message
            b.Security.Mode = WSFederationHttpSecurityMode.Message;

            // Set the Algorithm Suite to Basic256Rsa15
            b.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Basic256Rsa15;

            // Set NegotiateServiceCredential to true
            b.Security.Message.NegotiateServiceCredential = true;

            // Set IssuedKeyType to Symmetric
            b.Security.Message.IssuedKeyType = SecurityKeyType.SymmetricKey;

            // Set IssuedTokenType to SAML 1.1
            b.Security.Message.IssuedTokenType = "";

            // Extract the STS certificate from the certificate store
            X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);
            X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByThumbprint, "cd 54 88 85 0d 63 db ac 92 59 05 af ce b8 b1 de c3 67 9e 3f", false);

            // Create an EndpointIdentity from the STS certificate
            EndpointIdentity identity = EndpointIdentity.CreateX509CertificateIdentity(certs[0]);

            // Set the IssuerAddress using the address of the STS and the previously created EndpointIdentity
            b.Security.Message.IssuerAddress = new EndpointAddress(new Uri("http://localhost:8000/sts/x509"), identity);

            // Set the IssuerBinding to a WSHttpBinding loaded from config
            b.Security.Message.IssuerBinding = new WSHttpBinding("Issuer");

            // Set the IssuerMetadataAddress using the metadata address of the STS and the previously created EndpointIdentity
            b.Security.Message.IssuerMetadataAddress = new EndpointAddress(new Uri("http://localhost:8001/sts/mex"), identity);

            // Create a ClaimTypeRequirement
            ClaimTypeRequirement ctr = new ClaimTypeRequirement("", false);

            // Add the ClaimTypeRequirement to ClaimTypeRequirements

            // Return the created binding 
            return b;


Hope this helps.

share|improve this answer
Yes exactly what I needed, I did WSHttpBinding myBinding = new WSHttpBinding(), set up myBinding's properties, initialized EndpointAddress myEndpoint = new EndpointAddress(clientAddress); and set up my service ServiceReference1.Service1Client objService = new Service1Client(myBinding, myEndpoint); Thank you for your help :) – Rafał Saltarski Sep 6 '12 at 11:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.