我正在使用 WSTrust13 STS 服务来获取令牌。我在控制台应用程序中使用 addreference 机制为 WCF 服务创建了客户端。在向 WCF 发出请求时,请求到达了 WCF 服务,但它说“ID3007:带有命名空间''的元素'TokenType'无法识别。” 标头提取正确,但在处理邮件正文时显示此错误。
这是调用 WCF 服务的 C# 代码。
WSTrust13SyncClient 代理 = 新 WSTrust13SyncClient();
RequestSecurityTokenType request = new RequestSecurityTokenType();
proxy.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "XXXX");
var epa = new EndpointAddress(new Uri("https://XXX.svc/WSTrust13"),
new[] { AddressHeader.CreateAddressHeader("Id", string.Empty,000001)
});
proxy.Endpoint.Address = epa;
XmlElement TokenTypeelement = null;
XmlDocument doc = new XmlDocument();
TokenTypeelement = doc.CreateElement("TokenType");
TokenTypeelement.InnerText = "urn:oasis:names:tc:SAML:2.0:assertion";
List<XmlElement> lstElements = new List<XmlElement>();
lstElements.Add(TokenTypeelement);
request.Items =lstElements.ToArray();
try
{
RequestSecurityTokenResponseCollectionType response = proxy.Trust13Issue(request);
}
catch (Exception ex)
{
}
实际上,当我使用 SOAPUI 调用这个 WCF 时,它工作正常,下面是 SOAPUI 请求的主体。
我试图在 C# 代码中模仿相同的内容,将它们添加到请求中,但无法克服错误。
enter code here
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://docs.oasis-open.org/ws-sx/ws-trust/200512")]
public partial class RequestSecurityTokenType : object, System.ComponentModel.INotifyPropertyChanged {
private System.Xml.XmlElement[] itemsField;
private string contextField;
private System.Xml.XmlAttribute[] anyAttrField;
/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
public System.Xml.XmlElement[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
this.RaisePropertyChanged("Items");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType="anyURI")]
public string Context {
get {
return this.contextField;
}
set {
this.contextField = value;
this.RaisePropertyChanged("Context");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr {
get {
return this.anyAttrField;
}
set {
this.anyAttrField = value;
this.RaisePropertyChanged("AnyAttr");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
这是Issue 方法epxcted 的类对象。