未填充操作参数

本文关键字:参数 操作 填充 | 更新日期: 2023-09-27 17:56:12

我有一个WCF服务,其中包含以下服务''操作''数据协定。

namespace Enrollment
{    
    [ServiceContract(Namespace = "http://docs.oasis-open.org/ws-sx/ws-trust/200512")]
    public interface wstep
    {
        [OperationContract(Action = "http://schemas.microsoft.com/windows/pki/2009/01/enrollment/RST/wstep", Name = "RequestSecurityToken")]
        RequestSecurityTokenResponseCollection RequestSecurityToken(string TokenType, string RequestType, BinarySecurityToken binarySecurityToken, AdditionalContext additionalContext);
    }
    [DataContract(Namespace = "http://schemas.xmlsoap.org/ws/2006/12/authorization")]
    public class AdditionalContext
    {
        [DataMember]
        public List<ContextItem> contextItem { get; set; }
    }
    [DataContract(Namespace = "http://schemas.xmlsoap.org/ws/2006/12/authorization")]
    public class ContextItem
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember(Name="Value")]
        public object Item { get; set; }
    }
    [XmlRoot("BinarySecurityToken")]
    [DataContract(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", Name = "BinarySecurityToken")]
    public class BinarySecurityToken
    {
        [XmlAttribute("ValueType")]
        [DataMember(Name = "ValueType",Order=1)]        
        public string ValueType { get; set; }
        [XmlAttribute("EncodingType")]
        [DataMember(Name = "EncodingType", Order = 2)]
        public string EncodingType { get; set; }
    }
}
但是,

我看到客户端连接到服务,但是当我在服务中检查它们的值时,操作的最后两个参数 - 二进制安全令牌和附加上下文为空。我已经跟踪了客户端请求,并且我看到客户端正确发送了值。下面提到的是 SOAP 主体。

<s:Body>
    <wst:RequestSecurityToken>
        <wst:TokenType>http://schemas.microsoft.com/5.0.0.0/ConfigurationManager/Enrollment/DeviceEnrollmentToken</wst:TokenType>
        <wst:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</wst:RequestType>
        <wsse:BinarySecurityToken ValueType="http://schemas.microsoft.com/windows/pki/2009/01/enrollment#PKCS10" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd#base64binary">MIICcTCCAV0CAQAwMDEuMCwGA1UEAxMlQj=</wsse:BinarySecurityToken>
        <ac:AdditionalContext xmlns="http://schemas.xmlsoap.org/ws/2006/12/authorization">
            <ac:ContextItem Name="DeviceType">
                <ac:Value>MyDevice</ac:Value>
            </ac:ContextItem>
            <ac:ContextItem Name="ApplicationVersion">
                <ac:Value>18.10.6603.101</ac:Value>
            </ac:ContextItem>
        </ac:AdditionalContext>
    </wst:RequestSecurityToken>
</s:Body>

前两个参数正确显示。不知道发生了什么。

未填充操作参数

不能通过 WCF 发送object类型实例。您需要使用 ServiceKnownType 属性声明将通过服务发送的类型。

[DataMember(Name="Value")]
public object Item { get; set; }

例如,如果您知道对象只能是 X 类的实例,那么;

[ServiceKnownType(typeof(x))]
public interface wstep

此外,如果要更改序列化 xml 的结构,请参阅以下数据协定序列化与 xml 序列化