如何使用WSAddressing连接到服务WCF?

时间:2017-06-19 11:20:43

标签: c# .net wcf wshttpbinding ws-addressing

我正在尝试使用以下配置连接到WCF服务:

<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>

我尝试连接但该服务返回以下错误:

  

System.ServiceModel.Security.MessageSecurityException:另一方收到错误的不受保护或未受保护的错误。有关错误代码和更多详细信息,请参阅内部FaultException。 ---&GT; System.ServiceModel.FaultException:无法验证消息中的一个或多个安全令牌。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。

事实上,他们告诉我不正确的信息,因为代码是正确的,但您必须提供服务认可的凭据。

我通过以下方式解决了这个问题:

tf.summary.merge_all()