none
WCF - How to control the name spaces generated by web service in soap xml RRS feed

Answers

  • This didnot help.

    But I have figured out myself. The solutions is to define   [XmlSerializerFormat] in [ServiceContract] as below:

    [ServiceContract(Namespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")]
    [XmlSerializerFormat]
    public interface IDiscoveryService
    {
    }

    WIth this I am able produce the soap body same as MSFT protocol.


    K Raj


    • Marked as answer by Kanagal_Raj Friday, June 21, 2013 10:36 PM
    • Unmarked as answer by Kanagal_Raj Friday, June 21, 2013 10:36 PM
    • Edited by Kanagal_Raj Monday, June 24, 2013 4:17 PM corrections
    • Marked as answer by Haixia_XieModerator Friday, June 28, 2013 1:48 AM
    Friday, June 21, 2013 10:35 PM

All replies

  • Hi,

    >>How to avoid namespace "xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance" " in the <request> element?

    >>2. How can I avoid "i:" in XML element <i:EmailAddress> as <EmailAddress>. Similarly for <i:RequestVersion> as <RequestVersion>

    You may try set WebMessageBodyStyle as Bare for WebInvoke(BodyStyle=WebMessageBodyStyle.Bare ).

    >> 3. How can I add other soap headers to this xml?

    To achieve the goal, you can implements IClientMessageInspector to add a custom header to WCF calls.

    #How to add a custom header to every WCF calls?

    http://stackoverflow.com/questions/964433/how-to-add-a-custom-header-to-every-wcf-calls

    #How to: Inspect or Modify Messages on the Client

    http://msdn.microsoft.com/en-us/library/ms733786.aspx

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 21, 2013 9:21 AM
    Moderator
  • Setting BodyStyle=WebMessageBodyStyle.Bare is NOT avoiding the appending the "i:" to the xml element. 

    The operation contract definition is:

    [OperationContract]      

     [WebInvoke(Method = "POST",

    UriTemplate = "Discover?request=request",

    BodyStyle=WebMessageBodyStyle.Bare,

    ResponseFormat = WebMessageFormat.Xml)]   

    Result Discover(Request request);

    The xml generated is:
     <i:EmailAddress>g@g.com</i:EmailAddress>

    I am expecting the my xml element to look like:

     <EmailAddress>g@g.com</EmailAddress>


    K Raj


    • Edited by Kanagal_Raj Friday, June 21, 2013 1:06 PM formatting
    Friday, June 21, 2013 1:05 PM
  • On your data contract you have defined a namespace and that's the reason you are having a prefix in your request. Since its a different namespace than your service target namespace (which is used as default namespace).

    [DataContract(Namespace="http://www.w3.org/2001/XMLSchema-instance")]

    There is nothing wrong in having a prefix in your request. If you really wanna remove it than try removing data contract namespace

    Friday, June 21, 2013 2:30 PM
  • Vikas,

    If I remove the name space in data contract, I get different prefix "d4p1:". The microsoft has written the client  and there protocol document shows the request and response data without any prefixes. I believe if I develop web service and it is soap xml with prefix, i will lead to error when the MSFT client calls my server, right??

    As per my understanding, the namespace and xml element name should exactly with between Web Service and Web Service client, correct me if I am wrong?

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 

    <s:Header>   

    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">

    http://schemas.microsoft.com/windows/management/2012/01/enrollment/IDiscoveryService/Discover</Action> 

    </s:Header> 

    <s:Body>  

      <Discover xmlns="http://schemas.microsoft.com/windows/management/2012/01/enrollment/">

          <request xmlns:d4p1="http://schemas.datacontract.org/2004/07/DiscoveryWebService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

            <d4p1:EmailAddress>test</d4p1:EmailAddress> 

           <d4p1:RequestVersion>1</d4p1:RequestVersion> 

         </request>

        </Discover>

      </s:Body>

    </s:Envelope>



    K Raj

    Friday, June 21, 2013 2:47 PM
  • If you keep DataContract namespace same as servicecontract namespace then it should be ok
    Friday, June 21, 2013 8:27 PM
  • This didnot help.

    But I have figured out myself. The solutions is to define   [XmlSerializerFormat] in [ServiceContract] as below:

    [ServiceContract(Namespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment")]
    [XmlSerializerFormat]
    public interface IDiscoveryService
    {
    }

    WIth this I am able produce the soap body same as MSFT protocol.


    K Raj


    • Marked as answer by Kanagal_Raj Friday, June 21, 2013 10:36 PM
    • Unmarked as answer by Kanagal_Raj Friday, June 21, 2013 10:36 PM
    • Edited by Kanagal_Raj Monday, June 24, 2013 4:17 PM corrections
    • Marked as answer by Haixia_XieModerator Friday, June 28, 2013 1:48 AM
    Friday, June 21, 2013 10:35 PM
  • Hi,

    Thanks for your feedback and thanks for sharing your solution here, it will be very beneficial for other community members who have similar issue.

    Best Regards. 


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 25, 2013 2:47 AM
    Moderator
  • This solve my problem too! Thank you!
    Monday, September 14, 2020 6:35 PM