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

时间:2013-09-03 20:33:57

标签: c# wcf wse

我有一个用Java实现的Web服务,当前正由WSE 3.0客户端调用,我想从WSE迁移到WCF。使用标准工具,我创建了一个可以调用Web服务的客户端,但它返回一个SoapException,消息为“缺少必需参数值”。 Web服务使用HTTPS并且需要用户名和&要提供的密码。在现有的WSE客户端代码中,子类化 SecurityPolicyAssertion SendSecurityFilter 支持的凭据区域如下:

            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),我会收到“缺少必需参数值”的错误消息。

与上面配置此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>

提前致谢

1 个答案:

答案 0 :(得分:0)

如果没有样本,很难说出WSE3的SOAP消息在线路上的样子。尝试通过Fiddler获取并在此处发布。

通常,如果您使用SSL,请尝试以下方法:

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

如果您不使用ssl try CUB