none
Serialize object always adds xsi:Type="xsd:string" attribute

    Question

  • Hi all,

    I'm having the following problem: I'm trying to call a web service using the generated classes based on the wsdl file. Up until now this was working fine.  

    I now receive the following error from the service:

    javax.xml.ws.soap.SOAPFaultException: SOAP request message is invalid against the /WEB-INF/wsdl/d-offer.xsd XSD (validation error: UndeclaredPrefix: Cannot resolve 'xsd:string' as a QName: the prefix 'xsd' is not declared.)

    This message seems to be correct taking into account the message I send to the service:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header
       [header credentials and other stuff go here...
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <get-additional-connections xmlns=http://schema.bene.com/d-offer>
    <offer-context xsi:type="xsd:string">
    eNrtXNly2zoS/RWW5mXmARY2bi5ZVXZiO57ES8m+S2ZqygUQoM0bitSQ/DXIiL8sGU3H9DIJ0Q/.....
    </offer-context>
    <additional-Connections-requested travel-id="travel_0">
    <extension-direction>
    forward
    </extension-direction>
    </additional-Connections-requested>
    </get-additional-connections>
    </s:Body>
    </s:Envelope>

    I guess that the 'get-additional-connections' command is taken out of the SOAP body and processed by the service. Since the definition for the 'xsd' alias is defined on this body it is lost by the time the command is processed by the service.

    My question are:

    1. How do I remove the  xmlns:xsd="http://www.w3.org/2001/XMLSchema" from the SOAP Body tag

    2. How do I add this alias and namespace to the get-additional-connection tag

    3. How do I prevent that the xsi:type="xsd:string" is being generated by the XmlSerializer

    All help/tips/comments are highly appreciated since this is really blocking my progress.

    boris
    Wednesday, August 19, 2009 3:19 PM

Answers

  • Hi borisrogge ,

    Are you using the third-part tool to generate the Java client against WCF service ?

    This should be caused by some modification on the WCF service and the client didn't get updated. So please re-generate the client against the latest service WSDL and update it as well.

    Also for you questions. To add the alias and namespace to a method , you can define your service contract and operation contract like this:

        [ServiceContract(Namespace="http://localhost/JavaTest")]
        public interface IService1
        {
            [OperationContract(Action = "http://localhost/JavaTest/GetData")]
            string GetData(int value);
        }

    And in the SOAP message , this will be look like this:

    <s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Header>
        <a:Action s:mustUnderstand="1">http://localhost/JavaTest/GetData</a:Action>
        <a:MessageID>urn:uuid:90252532-31a3-443d-9abc-2f3f26f599dc</a:MessageID>
        <a:ReplyTo>
          <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
        </a:ReplyTo>
      </s:Header>
      <s:Body>
        <GetData xmlns="http://localhost/JavaTest">
          <value>3</value>
        </GetData>
      </s:Body>
    </s:Envelope>
    The SOAP message should be generated and some tags are defined strictly by default , so you don't need to change most of them. You just need to re-generate the client everytime the service contract or data contract is updated on WCF service.

    Hope this will be helpful.

    Thanks , Quan
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, August 24, 2009 10:00 AM

All replies

  • Did you just try regenerating your proxy fully.
    Also is the service or the client wcf?


    http://blogs.msdn.com/sajay
    Friday, August 21, 2009 1:44 AM
    Moderator
  • Hi borisrogge ,

    Are you using the third-part tool to generate the Java client against WCF service ?

    This should be caused by some modification on the WCF service and the client didn't get updated. So please re-generate the client against the latest service WSDL and update it as well.

    Also for you questions. To add the alias and namespace to a method , you can define your service contract and operation contract like this:

        [ServiceContract(Namespace="http://localhost/JavaTest")]
        public interface IService1
        {
            [OperationContract(Action = "http://localhost/JavaTest/GetData")]
            string GetData(int value);
        }

    And in the SOAP message , this will be look like this:

    <s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
      <s:Header>
        <a:Action s:mustUnderstand="1">http://localhost/JavaTest/GetData</a:Action>
        <a:MessageID>urn:uuid:90252532-31a3-443d-9abc-2f3f26f599dc</a:MessageID>
        <a:ReplyTo>
          <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
        </a:ReplyTo>
      </s:Header>
      <s:Body>
        <GetData xmlns="http://localhost/JavaTest">
          <value>3</value>
        </GetData>
      </s:Body>
    </s:Envelope>
    The SOAP message should be generated and some tags are defined strictly by default , so you don't need to change most of them. You just need to re-generate the client everytime the service contract or data contract is updated on WCF service.

    Hope this will be helpful.

    Thanks , Quan
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, August 24, 2009 10:00 AM