Webservice response using namespace prefix http://forums.asp.net/t/1249049.aspx/1?Webservice+response+using+namespace+prefix+Thu, 31 Jul 2008 16:47:18 -040012490492303589http://forums.asp.net/p/1249049/2303589.aspx/1?Webservice+response+using+namespace+prefix+Webservice response using namespace prefix <p>Hi,</p> <p>I'm developing a webservice right now. This webservice sends&nbsp;the following&nbsp;response;&nbsp; </p> <p>&lt;<font color="#800000">SupplyResponse</font><font color="#ff0000"> xmlns</font><font color="#0000ff">=&quot;</font>http://dummy.com<font color="#0000ff">&quot;&gt;<br> </font><font color="#0000ff">&nbsp; &lt;</font><font color="#800000">Body</font><font color="#ff0000"> xmlns</font><font color="#0000ff">=&quot;</font>urn:fec:messages:data:final:AStandardMessage:1_0<font color="#0000ff">&quot;&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">Supply</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">SellerParty</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">PrimaryID</font><font color="#ff0000"> xmlns</font><font color="#0000ff">=&quot;</font>urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2<font color="#0000ff">&quot;&gt;</font>12312312321<font color="#0000ff">&lt;/</font><font color="#800000">PrimaryID</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</font><font color="#800000">SellerParty</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">SupplyLine</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">LineDetails</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">ID</font><font color="#0000ff">&gt;</font>ANID01<font color="#0000ff">&lt;/</font><font color="#800000">ID</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">Status</font><font color="#0000ff">&gt;</font>true<font color="#0000ff">&lt;/</font><font color="#800000">Status</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</font><font color="#800000">LineDateTime</font><font color="#0000ff">&gt;</font>2008-04-17T08:58:11<font color="#0000ff">&lt;/</font><font color="#800000">LineDateTime</font><font color="#0000ff">&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff"><font color="#0000ff">&lt;</font><font color="#800000">Characteristics</font><font color="#0000ff">&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font><font color="#0000ff"><font color="#0000ff">&lt;</font><font color="#800000">ClassCode</font><font color="#ff0000"> xmlns</font><font color="#0000ff">=&quot;</font><font color="#000000">urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2</font><font color="#0000ff">&quot;&gt;</font><font color="#000000">L11</font><font color="#0000ff">&lt;/</font><font color="#800000">ClassCode</font><font color="#0000ff">&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></font><font color="#0000ff"><font color="#0000ff">&lt;</font><font color="#800000">ValueCode</font><font color="#ff0000"> xmlns</font><font color="#0000ff">=&quot;</font><font color="#000000">urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2</font><font color="#0000ff">&quot;&gt;</font><font color="#000000">010</font><font color="#0000ff">&lt;/</font><font color="#800000">ValueCode</font><font color="#0000ff">&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></font><font color="#0000ff"><font color="#0000ff">&lt;/</font><font color="#800000">Characteristics</font><font color="#0000ff">&gt;<br> </font></font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</font><font color="#800000">LineDetails</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</font><font color="#800000">SupplyLine</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp;&nbsp;&nbsp; &lt;/</font><font color="#800000">Supply</font><font color="#0000ff">&gt;<br> </font><font color="#0000ff">&nbsp; &lt;/</font><font color="#800000">Body</font><font color="#0000ff">&gt;<br> &lt;/</font><font color="#800000">SupplyResponse</font><font color="#0000ff">&gt;</font></p> <pre class="prettyprint"><p>What I want the response to be is:</p> <p>&lt;ns1:SupplyResponse xmlns=&quot;http://dummy.com&quot; <strong>xmlns:ns1=&quot;urn:fec:messages:data:final:AStandardMessage:1_0&quot; xmlns:ns2=&quot;urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2&quot;</strong>&gt;</p> <p> &lt;ns1:Body&gt;</p> <p> &lt;ns1:Supply&gt;</p> <p> &lt;ns1:SellerParty&gt;</p> <p> &lt;ns2:PrimaryID&gt;12312312321&lt;/ns2:PrimaryID&gt;</p> <p> &lt;/ns1:SellerParty&gt;</p> <p> &lt;ns1:SupplyLine&gt;</p> <p> &lt;ns1:LineDetails&gt;</p> <p> &lt;ns1:ID&gt;ANID01&lt;/ns1:ID&gt;</p> <p> &lt;ns1:Status&gt;true&lt;/ns1:Status&gt;</p> <p> &lt;ns1:LineDateTime&gt;2008-04-17T08:58:11&lt;/ns1:LineDateTime&gt;</p> <p> &lt;ns1:Characteristics&gt;<br> &lt;ns2:ClassCode&gt;L11&lt;/ns2:ClassCode&gt;<br> &lt;ns2:ValueCode&gt;010&lt;/ns2:ValueCode&gt;<br> &lt;/ns1:Characteristics&gt;<br> </p> <p> &lt;/ns1:LineDetails&gt;</p> <p> &lt;/ns1:SupplyLine&gt;</p> <p> &lt;/ns1:Supply&gt;</p> &lt;/ns1:Body&gt; <p>&lt;/ns1:SupplyResponse&gt;</p> <p> </p> <p>The main reason is messagesize; the example above is only a small part of the message my webservice is going to send. It can have up to thousands of SupplyLines. With every SupplyLine having an own namespace the messagesize will grow big time.</p> <p> I've been searching this forum, MSDN and Google for a solution but nothing seems to solve my problem so far. Can you help me?</p> <p></p> <p>Kind regards,</p> <p></p> <p>ThaYoung1!</p></pre> 2008-04-17T08:38:31-04:002310711http://forums.asp.net/p/1249049/2310711.aspx/1?Re+Webservice+response+using+namespace+prefixRe: Webservice response using namespace prefix <p>After spending hours of research I found the solution for my problem. I wanted to share this solution with the community in this post.</p> <p>To use namespace prefixes you add the following code in the SupplyResponse class;</p> <font size="2"> <p>[</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">XmlNamespaceDeclarations</font></font><font size="2">]<br> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">XmlSerializerNamespaces</font></font><font size="2"> xmlns<br> {<br> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">&nbsp; get<br> </font></font><font size="2">&nbsp; {<br> &nbsp;&nbsp;&nbsp; </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">XmlSerializerNamespaces</font></font><font size="2"> xsn = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">XmlSerializerNamespaces</font></font><font size="2">();<br> &nbsp;&nbsp;&nbsp; </font><font size="2">xsn.Add(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;ns1&quot;</font></font><font size="2">, </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;urn:fec:messages:data:final:AStandardMessage:0_1&quot;</font></font><font size="2">);<br> &nbsp;&nbsp;&nbsp; xsn.Add(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;ns2&quot;</font></font><font size="2">, </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2&quot;</font></font><font size="2">);<br> <br> &nbsp;&nbsp;&nbsp; </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">return</font></font><font size="2"> xsn;<br> &nbsp; </font><font size="2">}<br> &nbsp; </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">set</font></font><font size="2"> { </font><font color="#008000" size="2"><font color="#008000" size="2">/* needed for xml serialization */</font></font><font size="2"> }<br> }</font></p> <p><font size="2">Et voila; the message will be formatted with prefixes.</font></p> <p><font size="2">Kind Regards,</font></p> <p><font size="2"></font><font size="2">ThaYoung1!</p> </font> 2008-04-21T12:13:22-04:002310873http://forums.asp.net/p/1249049/2310873.aspx/1?Re+Webservice+response+using+namespace+prefixRe: Webservice response using namespace prefix ups, can be deleted<br> 2008-04-21T13:27:51-04:002528542http://forums.asp.net/p/1249049/2528542.aspx/1?Re+Webservice+response+using+namespace+prefixRe: Webservice response using namespace prefix <p>Does this really work? I haven't been able to get it working.</p> 2008-07-31T16:47:18-04:00