Jump to content
Sign in to follow this  
ahsan.asghar

Accepting Null Values in XML and/or WebService Call

Recommended Posts

Dear XML Schema Gurus,I am making an abstract WSDL to be given to another team who will make a web service based on abstract WSDL that I provide. As part of this exercise, I am making a WSDL file that has just the In, Out and Fault message declaration. While the In, Out message scehma is defined in an xsd file.In this web service, I want to keep about Seven (7) fields optional in web service call. I have tried doing that by puting minOccurs = "0" in the declaration of elements. Please find below the xsd code:=======================================<xs:element name="reserveABC"> <xs:complexType> <xs:sequence> <xs:element ref="ReserveABCIn"/> <xs:element ref="ReserveABCOut"/> <xs:element ref="ReserveABCFault"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="ReserveABCIn"> <xs:complexType> <xs:sequence> <xs:element ref="Blah" minOccurs="0"/> <xs:element ref="Blah1"/> <xs:element ref="User"/> <xs:element ref="OrderId"/> <xs:element ref="CustomerName"/> <xs:element ref="CustomerType"/> <xs:element ref="ServiceType" minOccurs="0"/> <xs:element ref="Reason" minOccurs="0"/> <xs:element ref="CreditLimit" minOccurs="0"/> <xs:element ref="WaiverCode" minOccurs="0"/> <xs:element ref="PaymentMethod" minOccurs="0"/> <xs:element ref="DepositFlag" minOccurs="0"/> <xs:element ref="CardType" minOccurs="0"/> <xs:element ref="CardNumber" minOccurs="0"/> <xs:element ref="CardName" minOccurs="0"/> <xs:element ref="CardExpiryDate" minOccurs="0"/> <xs:element ref="DealerCode" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="ReserveABCOut"> <xs:complexType> <xs:sequence> <xs:element ref="IsAvailable"/> <xs:element ref="Reason" minOccurs="0"/> <xs:element ref="Blah2" minOccurs="0"/> <xs:element ref="Blah3" minOccurs="0"/> <xs:element ref="Blah4" minOccurs="0"/> <xs:element ref="Blah5" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="ReserveABCFault"> <xs:complexType> <xs:sequence> <xs:element ref="Fault"/> </xs:sequence> </xs:complexType> </xs:element>.....................................................................................................................<xs:element name="Blah2" type="xBasic:cdm.Basic.Password"/><xs:element name="Blah3" type="xBasic:cdm.Basic.Password"/><xs:element name="Reason" type="xBasic:cdm.Basic.String"/><xs:element name="ServiceType" type="xBasic:cdm.Basic.String"/><xs:element name="OldYZ" type="xSim:cdm.Sim.YZ"/><xs:element name="CreditLimit" type="xAccount:cdm.BillingProfile.CreditLimitAmount"/><xs:element name="WaiverCode" type="xAccount:cdm.BillingProfile.WaiverCode"/><xs:element name="PaymentMethod" type="xAccount:cdm.BillingProfile.PaymentMethod"/><xs:element name="DepositFlag" type="xAccount:cdm.BillingProfile.DepositFlag"/><xs:element name="CardType" type="xAccount:cdm.BillingProfile.CreditCardType"/><xs:element name="CardNumber" type="xAccount:cdm.BillingProfile.CreditCardNumber"/><xs:element name="CardName" type="xAccount:cdm.BillingProfile.CreditCardName"/><xs:element name="CardExpiryDate" type="xAccount:cdm.BillingProfile.CreditCardExpirationDate"/><xs:element name="DealerCode" type="xAccount:cdm.AssetMgmt-Asset.MBLDealerCode"/>.....................................................................................................................Account.xsd:<xs:element name="CreditCardExpirationDate" type="xAccount:cdm.BillingProfile.CreditCardExpirationDate" nillable="true" minOccurs="0"/><xs:element name="CreditCardName" type="xAccount:cdm.BillingProfile.CreditCardName" minOccurs="0"/><xs:element name="CreditCardNumber" type="xAccount:cdm.BillingProfile.CreditCardNumber" minOccurs="0"/><xs:element name="CreditCardType" type="xAccount:cdm.BillingProfile.CreditCardType" minOccurs="0"/><xs:element name="MBLCreditLimit" type="xAccount:cdm.BillingProfile.MBLCreditLimit" minOccurs="0"/><xs:element name="WaiverCode" type="xAccount:cdm.BillingProfile.MBLSecurityWaiverCode" minOccurs="0"/><xs:element name="DepositFlag" type="xAccount:cdm.BillingProfile.DepositFlag" minOccurs="0"/><xs:element name="PaymentMethod" type="xAccount:cdm.BillingProfile.PaymentMethod" minOccurs="0"/>.....................................................................................................................=======================================When we called the web service with no value in the optional fields, it workes fine for string type fields. But it gives an error for fields of type Date, Double and Boolean. When I tried to investigate further, I was told by a colleague that minOccurs="0" means you can skip the tag. But if you do give the tag in webservice call, you will have to give a value. String type fields accept it because they take the empty input as null string. i.e. Tag exists and it has a value too, doesn't matter if the value is empty. But for a date, double, boolean etc fields, null/empty values give error.Would you please help how I can make these fields optional.Thanks & Regards,Ahsan Asghar

Share this post


Link to post
Share on other sites

What's the problem with not having the element? If you declare the second element optional, that doesn't mean the third one can't be there also.If for whatever reason you need to have all of them present, you can create your custom types that extend the XSD ones to allow an empty string as a value.

Share this post


Link to post
Share on other sites

Thanks for the quick response Boen Robot. Let me try and explain. The web service is called from an application that inputs all the values in one case and skips the optional values in another case. But for some reason it cannot skip tags. In the case where, application will leave the optional fields, it will not place values in tags but tags will stay in the call. When, empty tags are sent in web service call, Web Service on the other side gives a SOAP error:========================================================<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>Internal Error</faultstring> <detail> <Data> <ns0:LEException xmlns:ns0="http://www.tibco.com/schemas/Mobilink/SharedResources/Schemas/HouseKeeping"> <ns1:ErrorReport xmlns:ns1="http://www.tibco.com/pe/EngineTypes"> <StackTrace>Job-92110 Error in [services/HostAppName/ReserveXYZ/Interface/HTTPXMLServiceRequestFile.process/SOAPEventSource]Output data invalid at com.tibco.pe.core.ProcessGroup.a(ProcessGroup.java:157) at com.tibco.pe.core.ProcessGroup.eval(ProcessGroup.java:56) at com.tibco.pe.plugin.Activity.eval(Activity.java:209) at com.tibco.pe.core.TaskImpl.eval(TaskImpl.java:540) at com.tibco.pe.core.Job.a(Job.java:712) at com.tibco.pe.core.Job.k(Job.java:501) at com.tibco.pe.core.JobDispatcher$JobCourier.a(JobDispatcher.java:249) at com.tibco.pe.core.JobDispatcher$JobCourier.run(JobDispatcher.java:200)caused by: org.xml.sax.SAXException: validation error: data "" is not a valid double. A valid example is "12.78e-2". ({com.tibco.xml.validation}SIMPLE_E_INVALID_VALUE_FOR_TYPE) at /inputMessage[1]/inv:ReserveXYZIn[1]/inv:CreditLimit[1]com.tibco.xml.validation.exception.k: data "" is not a valid double. A valid example is "12.78e-2". at com.tibco.xml.validation.state.glue.f.a(LegacySimpleValidator.java:67) at com.tibco.xml.validation.state.c.a.int(ValidationJazz.java:1083) at com.tibco.xml.validation.state.c.a.a(ValidationJazz.java:489) at com.tibco.xml.validation.state.glue.e.xmlTreeNode(XmlTreeNodeValidationDriver.java:97) at com.tibco.xml.validation.state.glue.e.xmlTreeNode(XmlTreeNodeValidationDriver.java:92) at com.tibco.xml.validation.state.glue.e.xmlTreeNode(XmlTreeNodeValidationDriver.java:92) at com.tibco.xml.validation.state.glue.e.xmlTreeNode(XmlTreeNodeValidationDriver.java:129) at com.tibco.xml.xdata.bind.BindingRunner.validate(Unknown Source) at com.tibco.pe.core.ProcessGroup.a(ProcessGroup.java:150) at com.tibco.pe.core.ProcessGroup.eval(ProcessGroup.java:56) at com.tibco.pe.plugin.Activity.eval(Activity.java:209) at com.tibco.pe.core.TaskImpl.eval(TaskImpl.java:540) at com.tibco.pe.core.Job.a(Job.java:712) at com.tibco.pe.core.Job.k(Job.java:501) at com.tibco.pe.core.JobDispatcher$JobCourier.a(JobDispatcher.java:249) at com.tibco.pe.core.JobDispatcher$JobCourier.run(JobDispatcher.java:200) ................................... ................................... ...................................=================================================I have done the same as you suggested, to make the string version of each optional field. But I posted my question on this forum in parallel, hoping to get a cleaner solution.Thanks & Regards,Ahsan

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...