locked
Webservice response using namespace prefix RRS feed

  • Question

  • User-1970872809 posted

    Hi,

    I'm developing a webservice right now. This webservice sends the following response; 

    <SupplyResponse xmlns="http://dummy.com">
      <Body xmlns="urn:fec:messages:data:final:AStandardMessage:1_0">
        <Supply>
          <SellerParty>
            <PrimaryID xmlns="urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2">12312312321</PrimaryID>
          </SellerParty>
          <SupplyLine>
            <LineDetails>
              <ID>ANID01</ID>
              <Status>true</Status>
              <LineDateTime>2008-04-17T08:58:11</LineDateTime>
             
    <Characteristics>
               
    <ClassCode xmlns="urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2">L11</ClassCode>
               
    <ValueCode xmlns="urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2">010</ValueCode>
              
    </Characteristics>
            </LineDetails>
          </SupplyLine>
        </Supply>
      </Body>
    </
    SupplyResponse>

    What I want the response to be is:

     

    <ns1:SupplyResponse xmlns="http://dummy.com" xmlns:ns1="urn:fec:messages:data:final:AStandardMessage:1_0" xmlns:ns2="urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2">

    <ns1:Body>

    <ns1:Supply>

    <ns1:SellerParty>

    <ns2:PrimaryID>12312312321</ns2:PrimaryID>

    </ns1:SellerParty>

    <ns1:SupplyLine>

    <ns1:LineDetails>

    <ns1:ID>ANID01</ns1:ID>

    <ns1:Status>true</ns1:Status>

    <ns1:LineDateTime>2008-04-17T08:58:11</ns1:LineDateTime>

              <ns1:Characteristics>
               
    <ns2:ClassCode>L11</ns2:ClassCode>
               
    <ns2:ValueCode>010</ns2:ValueCode>
              
    </ns1:Characteristics>

    </ns1:LineDetails>

    </ns1:SupplyLine>

    </ns1:Supply>

    </ns1:Body>

    </ns1:SupplyResponse>

     

    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.

     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?

     

    Kind regards,

     

    ThaYoung1!

    Thursday, April 17, 2008 4:38 AM

Answers

  • User-1970872809 posted

    After spending hours of research I found the solution for my problem. I wanted to share this solution with the community in this post.

    To use namespace prefixes you add the following code in the SupplyResponse class;

    [XmlNamespaceDeclarations]
    public XmlSerializerNamespaces xmlns
    {
      get
      {
       
    XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
       
    xsn.Add("ns1", "urn:fec:messages:data:final:AStandardMessage:0_1");
        xsn.Add(
    "ns2", "urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2");

       
    return xsn;
     
    }
     
    set { /* needed for xml serialization */ }
    }

    Et voila; the message will be formatted with prefixes.

    Kind Regards,

    ThaYoung1!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 21, 2008 8:13 AM

All replies

  • User-1970872809 posted

    After spending hours of research I found the solution for my problem. I wanted to share this solution with the community in this post.

    To use namespace prefixes you add the following code in the SupplyResponse class;

    [XmlNamespaceDeclarations]
    public XmlSerializerNamespaces xmlns
    {
      get
      {
       
    XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
       
    xsn.Add("ns1", "urn:fec:messages:data:final:AStandardMessage:0_1");
        xsn.Add(
    "ns2", "urn:un:unece:uncefact:data:draft:ReusableAggregateBusinessInformationEntity:2");

       
    return xsn;
     
    }
     
    set { /* needed for xml serialization */ }
    }

    Et voila; the message will be formatted with prefixes.

    Kind Regards,

    ThaYoung1!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 21, 2008 8:13 AM
  • User-1016791496 posted
    ups, can be deleted
    Monday, April 21, 2008 9:27 AM
  • User-1548088970 posted

    Does this really work? I haven't been able to get it working.

    Thursday, July 31, 2008 12:47 PM