0

我有一个用 Java 实现的 Web 服务,当前由 WSE 3.0 客户端调用,我想从 WSE 迁移到 WCF。使用标准工具,我创建了一个可以调用 Web 服务的客户端,但它返回一个 SoapException 并显示“缺少必需的参数值”消息。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),我会收到相同的错误消息“缺少必需的参数值”。

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

提前致谢

4

1 回答 1

0

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

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

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

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

于 2013-09-03T20:39:43.067 回答