简体   繁体   中英

Can I remove the default namespace when creating raw Soap XML?

I'm trying to send a soap request to a WCF service. I am building the soap request using the System.ServiceModel.Channels.Message.CreateMessage() method.

I haven't gotten super deep into building the body, but here is what I have...

Message msg = Message.CreateMessage( MessageVersion.Soap11WSAddressing10, "MethodName" );
msg.Headers.MessageId = new UniqueId( Guid.NewGuid().ToString() );
msg.Headers.Add( Message.CreateHeader( "Security", "",
    new Security()
    {
        TimeStamp = new TimeStampType() {
            Created = DateTime.Now,
            Expires = Created.AddDays( 1 )
        },
        UsernameToken = new UsernameToken() {
            Username = "stackoverflow",
            Password = new Password() {
                Type = "hashed",
                Value = "Password"
            }
        }
     } ) ) );

string s = msg.ToString();

When I run this, I get the following output. I'm using the Visual Studio XML Visualizer btw.

<s:Envelope>
    <s:Header>
        <Action>MethodName</Action>
        <MessageID>GUIDVALUE</MessageID>
        <Security>
            <Timestamp xmlns="http://schemas.datacontract.org/2004/07/ConsoleApplication1">
               .....
    </s:Header>
    <s:Body />
</s:Envelope>

My question is, can I remove xmlns="http://schemas.datacontract.org/2004/07/ConsoleApplication1" from the xml? It shows up in Timestamp and in UsernameToken.

Thanks

在包装安全性和时间戳的类中的datacontract中将Namespace设置为空

  [DataContract(Namespace = "")]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM