title: Invoke a SOAP method with namespace prefixes
body: <p>My C# web service client sends following soap message to Java-based web service:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;soap:Body&gt;
  &lt;getData&gt;
  &lt;request&gt;
  &lt;requestParameters xmlns="http://b..."&gt;
  &lt;equals&gt;
  ...
  &lt;/equals&gt;
  &lt;/requestParameters&gt;
  &lt;/request&gt;
  &lt;/getData&gt;
  &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt; 
  </code></pre>
  
  <p>and Java-based web service returns error: </p>
  
  <blockquote>
  <pre><code>500 Internal Server Error
  ...
  Cannot find dispatch method for {}getData
  ...
  </code></pre>
  </blockquote>
  
  <p>Client written in Java, which works, sends the following message:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;soap:Body&gt;
  &lt;ns2:getData xmlns:ns2="http://a..."&gt;
  &lt;ns2:request&gt;
  &lt;ns3:requestParameters xmlns:ns3="http://b..."&gt;
  &lt;ns3:equals&gt;
  ...
  &lt;/ns3:equals&gt;
  &lt;/ns3:requestParameters&gt;
  &lt;/ns2:request&gt;
  &lt;/ns2:getData&gt;
  &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt; 
  </code></pre>
  
  <p>Is there an easy way in C# to send SOAP messages the same way Java client sends: with namespace prefixes?</p>
  
  <p>Following is C# code that sends message:</p>
  
  <pre><code>// class MyService is auto-generated using wsdl.exe tool
  MyService service = new MyService();
  
  RequestMessage request = new RequestMessage();
  ...
  
  ResponseMessage response = service.getData(request);
  ...
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>Here is RequestMessage class:</p>
  
  <pre><code>/// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://uri.etsi.org/02657/v1.5.1#/RetainedData")]
  public partial class RequestMessage
  {
  
      private byte[] requestPriorityField;
  
      private RequestConstraints requestParametersField;
  
      private string deliveryPointHIBField;
  
      private string maxHitsField;
  
      private NationalRequestParameters nationalRequestParametersField;
  
      private System.Xml.XmlElement anyField;
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute(DataType="hexBinary", Order=0)]
      public byte[] requestPriority
      {
          get
          {
              return this.requestPriorityField;
          }
          set
          {
              this.requestPriorityField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute(Order=1)]
      public RequestConstraints requestParameters
      {
          get
          {
              return this.requestParametersField;
          }
          set
          {
              this.requestParametersField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute(Order=2)]
      public string deliveryPointHIB
      {
          get
          {
              return this.deliveryPointHIBField;
          }
          set
          {
              this.deliveryPointHIBField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute(DataType="integer", Order=3)]
      public string maxHits
      {
          get
          {
              return this.maxHitsField;
          }
          set
          {
              this.maxHitsField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute(Order=4)]
      public NationalRequestParameters nationalRequestParameters
      {
          get
          {
              return this.nationalRequestParametersField;
          }
          set
          {
              this.nationalRequestParametersField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAnyElementAttribute(Order=5)]
      public System.Xml.XmlElement Any
      {
          get
          {
              return this.anyField;
          }
          set
          {
              this.anyField = value;
          }
      }
  }
  </code></pre>
  
  <p>UPDATE #2:</p>
  
  <p>The reason why Java-based web service didn't like my C# client produced SOAP message is not omission of namespace prefixes, but only because of omission of xmlns in getData element, so if my message looks like this:</p>
  
  <pre><code>...
  &lt;getData xmlns="http://a..."&gt;
  ...
  &lt;/getData&gt;
  ...
  </code></pre>
  
  <p>it works!</p>
  
  <p>I managed to put xmlns inside getData by manually editing SoapRpcMethodAttribute in wsdl.exe-produced source code. Here is excerpt:</p>
  
  <pre><code>/// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Web.Services.WebServiceBindingAttribute(
      Name="AxxxPortTypeBinding", Namespace="http://a...")]
  public partial class AxxxService 
      : System.Web.Services.Protocols.SoapHttpClientProtocol {
  
      ...
  
      /// &lt;remarks/&gt;
      [System.Web.Services.Protocols.SoapRpcMethodAttribute(
          "http://a.../getData", 
          RequestNamespace = "http://a...", 
          ResponseNamespace = "http://a...",
          Use = System.Web.Services.Description.SoapBindingUse.Literal)]
      [return: System.Xml.Serialization.XmlElementAttribute("response")]
      public ResponseMessage getData(RequestMessage request) {
          object[] results = this.Invoke("getData", new object[] {
                      request});
          return ((ResponseMessage)(results[0]));
      }
  
      ...
  }
  </code></pre>
  
  <p>Before my change, SoapRpcMethodAttribute had following constructor:</p>
  
  <pre><code>[System.Web.Services.Protocols.SoapRpcMethodAttribute(
      "", RequestNamespace = "", ResponseNamespace = "",
      Use = System.Web.Services.Description.SoapBindingUse.Literal)]
  </code></pre>
  
  <p>Now, the question is: what to put in WSDL file so that SoapRpcMethodAttribute have those strings in constructor (filled by the wsdl.exe tool) in the first place?</p>