WsTrust.Trust13Issue - 设置 RequestSecurityTokenType -ID3007:无法识别具有命名空间“”的元素 'TokenType'
WsTrust.Trust13Issue - setting RequestSecurityTokenType -ID3007: The element 'TokenType' with namespace '' is unrecognized
我正在使用 WSTrust13 STS 服务来获取令牌。我在控制台应用程序中使用 addreference 机制为 WCF 服务创建了客户端。在向 WCF 发出请求时,请求已到达 WCF 服务,但它表示 "ID3007: The element 'TokenType' with namespace '' is unrecognized." headers 已正确提取,但在处理消息的 body 时显示此错误。
这是调用 WCF 服务的 C# 代码。
WSTrust13SyncClient 代理 = new 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 请求的 body。
我正在尝试在 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 方法所期望的 class object。
想通了,我还需要在创建 XMLElement 时添加命名空间。就是这样解决了问题。
我正在使用 WSTrust13 STS 服务来获取令牌。我在控制台应用程序中使用 addreference 机制为 WCF 服务创建了客户端。在向 WCF 发出请求时,请求已到达 WCF 服务,但它表示 "ID3007: The element 'TokenType' with namespace '' is unrecognized." headers 已正确提取,但在处理消息的 body 时显示此错误。
这是调用 WCF 服务的 C# 代码。
WSTrust13SyncClient 代理 = new 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 请求的 body。
我正在尝试在 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 方法所期望的 class object。
想通了,我还需要在创建 XMLElement 时添加命名空间。就是这样解决了问题。