将WSE客户端迁移到WCF-如何替换SecurityPolicyAssertion和UsernameToken

本文关键字:替换 SecurityPolicyAssertion UsernameToken 何替换 客户端 WSE 迁移 WCF- | 更新日期: 2023-09-27 18:30:01

我有一个用Java实现的web服务,它目前正由WSE 3.0客户端调用,我想从WSE迁移到WCF。使用标准工具,我创建了一个可以调用web服务的客户端,但它返回一个SoapException,并显示一条消息"Required parameter value is missing"。该web服务使用HTTPS并且需要用户名&要提供的密码。在现有的WSE客户端代码中,通过子类化SecurityPolicyAssertionSendSecurityFilter支持的凭据区域,如下所示:

            public class UTClientAssertion : SecurityPolicyAssertion
            {
                public UTClientAssertion()
                {
                }
                public override SoapFilter CreateClientOutputFilter(FilterCreationContext context)
                {
                    return new ClientOutputFilter(this, context);
                }
                public override SoapFilter CreateClientInputFilter(FilterCreationContext context)
                {
                    // we don't provide ClientInputFilter
                    return null;
                }
                public override SoapFilter CreateServiceInputFilter(FilterCreationContext context)
                {
                    // we don't provide any processing for web service side
                    return null;
                }
                public override SoapFilter CreateServiceOutputFilter(FilterCreationContext context)
                {
                    // we don't provide any processing for web service side
                    return null;
                }
                #region ClientOutputFilter
                class ClientOutputFilter : SendSecurityFilter
                {
                    public ClientOutputFilter(UTClientAssertion parentAssertion, FilterCreationContext context)
                        : base(parentAssertion.ServiceActor, false, parentAssertion.ClientActor)
                    {
                    }
                    public override void SecureMessage(SoapEnvelope envelope, Security security)
                    {
                        UsernameToken token = new UsernameToken("UserName", "Password", PasswordOption.SendPlainText);
                        security.Tokens.Add(token);
                        security.MustUnderstand = false;
                    }
                }
                #endregion

这些类应用于客户端中生成的代理类,如下所示:

                // Create the web service client
                ListService objListSvc = new ListService();
                //code to set up the security policy and user assertion
                UTClientAssertion objAssertion = new UTClientAssertion();
                // create policy, add the assertion, and set it on the web service
                Policy objPolicy = new Policy();
                objPolicy.Assertions.Add(objAssertion);
                objListSvc.SetPolicy(objPolicy);

我发现,如果我编辑WSE客户端代码以删除行objListSvc.SetPolicy(objPolicy),我会得到相同的错误消息"Required parameter value is missing"。

与上面配置此web服务的用户名和密码的WSE代码匹配的等效WCF配置/代码是什么?正在使用的WCF配置是生成的默认配置:

        <basicHttpBinding>
            <binding name="ListBinding" 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="UserName" algorithmSuite="Default" />
              </security>
            </binding>
        </basicHttpBinding>

提前感谢

将WSE客户端迁移到WCF-如何替换SecurityPolicyAssertion和UsernameToken

如果没有WSE3的SOAP消息在网络上的外观示例,很难判断。尝试通过Fiddler获得一个并在此处发布。

通常,如果您使用SSL,请尝试以下操作:

<bindings>
        <basicHttpBinding>
            <binding name="NewBinding0">
                <security mode="TransportWithMessageCredential " />
            </binding>
        </basicHttpBinding>
</bindings>

如果不使用ssl,请尝试CUB。