wcfwifws-trust

WsTrust.Trust13Issue - setting RequestSecurityTokenType -ID3007: The element 'TokenType' with namespace '' is unrecognized


I am using WSTrust13 STS service to get the token. I created the client for WCF service using addreference mechanism in my console application. while making the request to WCF the reqest reached WCF service but it says that "ID3007: The element 'TokenType' with namespace '' is unrecognized." headers extracted correctly but while handling the body of the message it shows this error.

here is C# code which is calling WCF service.

WSTrust13SyncClient proxy = 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)
        {

        }

Actually, when I call this WCF using SOAPUI it works fine and following is the body of the SOAPUI request. enter image description here

I am trying to mimic the same in C# code to add these into request but unable and getting above error.

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));
        }
    }
}

this is the class object that is epxcted by Issue method.


Solution

  • figured it, I need to add the namespace as well while creating the XMLElement. thats it which blows the problem away.