0

I'm trying to connect to a WCF service with the following configuration:

<wsp:Policy wsu:Id="WSHttpBinding_IService_policy">
    <wsp:ExactlyOne>
        <wsp:All>
            <wsoma:OptimizedMimeSerialization xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"/>
            <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                <wsp:Policy>
                    <sp:TransportToken>
                        <wsp:Policy>
                            <sp:HttpsToken RequireClientCertificate="false"/>
                        </wsp:Policy>
                    </sp:TransportToken>
                    <sp:AlgorithmSuite>
                        <wsp:Policy>
                            <sp:Basic256/>
                        </wsp:Policy>
                    </sp:AlgorithmSuite>
                    <sp:Layout>
                        <wsp:Policy>
                            <sp:Strict/>
                        </wsp:Policy>
                    </sp:Layout>
                    <sp:IncludeTimestamp/>
                </wsp:Policy>
            </sp:TransportBinding>
            <sp:EndorsingSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                <wsp:Policy>
                    <sp:SecureConversationToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                        <wsp:Policy>
                            <sp:BootstrapPolicy>
                                <wsp:Policy>
                                    <sp:SignedParts>
                                        <sp:Body/>
                                        <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                                        <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                                        <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                                        <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                                        <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                                        <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                                        <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                                    </sp:SignedParts>
                                    <sp:EncryptedParts>
                                        <sp:Body/>
                                    </sp:EncryptedParts>
                                    <sp:TransportBinding>
                                        <wsp:Policy>
                                            <sp:TransportToken>
                                                <wsp:Policy>
                                                    <sp:HttpsToken RequireClientCertificate="false"/>
                                                </wsp:Policy>
                                            </sp:TransportToken>
                                            <sp:AlgorithmSuite>
                                                <wsp:Policy>
                                                    <sp:Basic256/>
                                                </wsp:Policy>
                                            </sp:AlgorithmSuite>
                                            <sp:Layout>
                                                <wsp:Policy>
                                                    <sp:Strict/>
                                                </wsp:Policy>
                                            </sp:Layout>
                                            <sp:IncludeTimestamp/>
                                        </wsp:Policy>
                                    </sp:TransportBinding>
                                    <sp:SignedSupportingTokens>
                                        <wsp:Policy>
                                            <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                                                <wsp:Policy>
                                                    <sp:WssUsernameToken10/>
                                                </wsp:Policy>
                                            </sp:UsernameToken>
                                        </wsp:Policy>
                                    </sp:SignedSupportingTokens>
                                    <sp:Wss11>
                                        <wsp:Policy/>
                                    </sp:Wss11>
                                    <sp:Trust10>
                                        <wsp:Policy>
                                            <sp:MustSupportIssuedTokens/>
                                            <sp:RequireClientEntropy/>
                                            <sp:RequireServerEntropy/>
                                        </wsp:Policy>
                                    </sp:Trust10>
                                </wsp:Policy>
                            </sp:BootstrapPolicy>
                        </wsp:Policy>
                    </sp:SecureConversationToken>
                </wsp:Policy>
            </sp:EndorsingSupportingTokens>
            <sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                <wsp:Policy/>
            </sp:Wss11>
            <sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                <wsp:Policy>
                    <sp:MustSupportIssuedTokens/>
                    <sp:RequireClientEntropy/>
                    <sp:RequireServerEntropy/>
                </wsp:Policy>
            </sp:Trust10>
            <wsaw:UsingAddressing/>
        </wsp:All>
    </wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types>

I tried to connect but the service returns the following error:

System.ServiceModel.Security.MessageSecurityException: Incorrectly unprotected or unprotected error received on the other side. For the error code and further details, see Internal FaultException. ---> System.ServiceModel.FaultException: Unable to validate one or more security tokens in the message.

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
antann78
  • 21
  • 3

1 Answers1

0

I solved the problem.

In fact, they had informed me of the incorrect information because the code was correct but you have to provide credentials recognized by the service.

I trivially solved this as follows:

try
{
                var c = new Services.ServiceClient();

                c.ClientCredentials.UserName.UserName = "test@tin.it";
                c.ClientCredentials.UserName.Password= "pass";

                Result ra = c.CheckCode("123");

                if (ra.State == MessageStatusType.OK)
                {
                    tbText.Text = "Connection ok: " + ra.TextState;
                }
                else
                {
                    tbText.Text = "Connection ko: " + ra.TextState;
                }
}
catch (Exception ex)
{
    tbText.Text = ex.ToString();
}
antann78
  • 21
  • 3