none
Understanding Namespace for ServiceContract, ServiceBehavior, DataContract

    Question

  • I would like to understand about Namespaces when used in conjunction with the various attributes.  The <b: really annoys me.  I would ultimately like my output to look like the last example. 

    Through trying to find information on Namespaces, I ran across a blurb about you shouldn't apply Namespaces directly to the ServiceContract and should be applied to the service via the ServiceBehavior attribute.  I was unable to get the desired output without applying it to the ServiceContract. 

    Is there some more formal documentation on Name and Namespace other than the sparse information in the VS help? 

    I'm looking for information on

    • Why do I want to use a Namespace. 
    • Under what circumstances I would want to use it?
    • What happens if I do use it?
    • How will this affect clients if I change it?
    • Do I ever need to change it?
    • Why would I want to change it?

    Each of the examples below show the attribute settings that I used and the output that was generated. 

    ===============================

    [ServiceContract( Namespace = "http://www.MyCompany.com/" )]
    [ServiceBehavior()]
    [DataContract()]

    <ReturnDataResponse xmlns="http://www.MyCompany.com/">
      <ReturnDataResult
        xmlns:b="http://schemas.datacontract.org/2004/07/Service.Interface"
        xmlns:i="http://www.w3.org/2001/XMLSchema instance">
        <b:Address>
          <b:City>Raleigh</b:City>
          <b:State>NC</b:State>
          <b:Street>123 Main Street</b:Street>
          <b:Zip>27615</b:Zip>
        </b:Address>
        <b:Name>
          <b:FirstName>Bob</b:FirstName>
          <b:LastName>The Builder</b:LastName>
        </b:Name>
       </ReturnDataResult>
    </ReturnDataResponse>

    ===============================

    [ServiceContract()]
    [ServiceBehavior( Namespace = "http://www.MyCompany.com/" )]
    [DataContract()]

    <ReturnDataResponse xmlns="http://tempuri.org/">
      <ReturnDataResult
        xmlns:b="http://schemas.datacontract.org/2004/07/Service.Interface"
        xmlns:i="http://www.w3.org/2001/XMLSchema instance">
        <b:Address>
          <b:City>Raleigh</b:City>
          <b:State>NC</b:State>
          <b:Street>123 Main Street</b:Street>
          <b:Zip>27615</b:Zip>
        </b:Address>
        <b:Name>
          <b:FirstName>Bob</b:FirstName>
          <b:LastName>The Builder</b:LastName>
        </b:Name>
      </ReturnDataResult>
    </ReturnDataResponse>

    ===============================

    [ServiceContract()]
    [ServiceBehavior( Namespace = "http://www.MyCompany.com/" )]
    [DataContract( Namespace = "http://www.MyCompany.com/" )]

    <ReturnDataResponse xmlns="http://tempuri.org/">
      <ReturnDataResult
        xmlns:b="http://www.MyCompany.com/"
        xmlns:i="http://www.w3.org/2001/XMLSchema instance">
        <b:Address>
          <b:City>Raleigh</b:City>
          <b:State>NC</b:State>
          <b:Street>123 Main Street</b:Street>
          <b:Zip>27615</b:Zip>
        </b:Address>
        <b:Name>
          <b:FirstName>Bob</b:FirstName>
          <b:LastName>The Builder</b:LastName>
        </b:Name>
      </ReturnDataResult>
    </ReturnDataResponse>

    ===============================

    [ServiceContract( Namespace = "http://www.MyCompany.com/" )]
    [ServiceBehavior()]
    [DataContract( Namespace = "http://www.MyCompany.com/" )]


    <ReturnDataResponse xmlns="http://www.MyCompany.com/">
      <ReturnDataResult xmlns:i="http://www.w3.org/2001/XMLSchema instance">
        <Address>
          <City>Raleigh</City>
          <State>NC</State>
          <Street>123 Main Street</Street>
          <Zip>27615</Zip>
        </Address>
        <Name>
          <FirstName>Bob</FirstName>
          <LastName>The Builder</LastName>
        </Name>
      </ReturnDataResult>
    </ReturnDataResponse>

    ===============================

     

     

     

    Tuesday, July 18, 2006 2:24 PM

Answers

All replies