title: Access to XML prefixes in WCF
body: <p>I am trying to pass several XAML document fragments to a SOAP <code>basicHttpBinding</code> web service as <code>XElement</code> instances.</p>
  
  <pre class="lang-cs prettyprint-override"><code>[ServiceContract(Namespace = "someNamespace")]
  interface IMyService
  {
      [OperationContract]
      void Start(XElement someArgument);
  }
  </code></pre>
  
  <p>The messages end up with a format like below.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:exec="someNamespace"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:system="clr-namespace:System;assembly=mscorlib"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;exec:Start&gt;
           &lt;exec:someArgument&gt;
              &lt;SomeObject xmlns="someAnotherNamespace"
                          xmlns:myPrefix="yetAnotherNamespace"&gt;
                 &lt;AnotherObject Property="{myPrefix:Foo}" /&gt;
              &lt;/SomeObject&gt;
           &lt;/exec:someArgument&gt;
        &lt;/exec:Start&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>All is well is <code>myPrefix</code> is defined on the root of the XAML island (i.e. <code>&lt;SomeObject&gt;</code>). However, if I move the namespace declaration to the <code>&lt;soapenv:Envelope&gt;</code> (which is obviously permitted, barring any prefix clashes)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:exec="someNamespace"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:system="clr-namespace:System;assembly=mscorlib"
      xmlns:myPrefix="yetAnotherNamespace"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;exec:Start&gt;
           &lt;exec:someArgument&gt;
              &lt;SomeObject xmlns="someAnotherNamespace"&gt;
                 &lt;AnotherObject Property="{myPrefix:Foo}" /&gt;
              &lt;/SomeObject&gt;
           &lt;/exec:someArgument&gt;
        &lt;/exec:Start&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>The resulting <code>XElement</code> no longer has knowledge about that the URI <code>yetAnotherNamespace</code> is actually represented by the prefix <code>myPrefix</code>. Instead, a generic prefix (<code>p2</code>) is assigned.</p>
  
  <p>Therefore, <code>XamlXmlReader</code> will be unable to read the markup extension <code>{myPrefix:Foo}</code>, since it is still associated with the old prefix <code>myPrefix</code> instead of <code>p2</code>. Indeed, for XML processing inside of WCF, the markup extension was a string attribute, and received no specific treatment for namespace prefixes.</p>
  
  <p>The behavior in which successful reading of the XML island depends on the placement of <code>xmlns:</code> prefix declarations is highly confusing. <em>Is there a way to re-map prefixes somehow for more correct behavior?</em></p>