私はSOAPリクエストのためにヘッダを作成する必要があります。検索後、私はXMLで私のヘッダーリクエストを生成するのに成功しましたが、私は自分のXMLタグにプレフィックスが必要です。C#でXmlRootオブジェクトの接頭辞を使用してSerialise XMLを使用するにはどうすればよいですか?
実は、私はこれを生成した:
<TimeStamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="TimeStamp-2">
<Created>2016-03-22T10:10:55.710Z</Created>
<Expires>2016-03-22T11:10:55.710Z</Expires>
</TimeStamp>
そして、私はそれを持っている必要があります:私はこのトピック(How can I pass a username/password in the header to a SOAP WCF Service)のための私のクラスを作成し、私のXMLを生成するに触発された
<wsu:TimeStamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="TimeStamp-2">
<Created>2016-03-22T10:10:55.710Z</Created>
<Expires>2016-03-22T11:10:55.710Z</Expires>
</wsu:TimeStamp>
。ここで
は、私のバージョンがあります:
class SecurityHeader : MessageHeader
{
public override string Name
{
get { return "Security"; }
}
public override string Namespace
{
get { return "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; }
}
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
XmlSerializer serializer1 = new XmlSerializer(typeof(TimeStamp));
serializer1.Serialize(Console.Out, new TimeStamp(), ns);
}
}
[XmlRoot("TimeStamp",Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public class TimeStamp
{
public TimeStamp()
{
Id = "TimeStamp-2";
Created = new Created() { Value = Created.GenerateTimeStampCreation() };
Expires = new Expires() { Value = Expires.GenerateTimeStampExpiration() };
}
[XmlAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")]
public string Id { get; set; }
[XmlElement]
public Created Created { get; set; }
[XmlElement]
public Expires Expires { get; set; }
}
実は、私は自分で自分の問題を解決します。私の解決策はあなたの最初の問題で似ています。私はOnWriteHeaderContentsメソッドを使用します(ただし、このトピックでは指定しませんでした)。私はちょっと急いでいるので、週に私のメッセージを編集して、あなたの他の問題を研究し、自分のコードとヘッダーを改善してください。ありがとう@ DB2 – Adaok