Hello Ege,
The ObjectFactory class which is generated out of schema includes
complex types such as PersonInformationDTO, PersonNameDTO and so on.
All types which are of scalar (boolean, int, ...) and derivative (simple
content, scalar type extensions) will be ommited as they are mapped to
aproprieate Java types which are part of Java standard library.
You can find in generated code you pasted:
protected Boolean personInformationProtected
This is scalar value coming out of xs:boolean type defined in schema.
To me it looks like schema processing or JAXB runtime misses namespace
information. Error you pasted indicate *<{}PersonInformationProtected>*
which does not include namespace.
Can you confirm if service you work with is compatible with WS-I Basic
Profile? You can use publicly available tools from Web Services
Interopability Organization: http://ws-i.org/deliverables/testingtools.html
Kind regards,
Łukasz
--
Code-House
http://code-house.org/
On 19.01.2023 13:16, Ege, Bernhard wrote:
I have created java files using wsdl2java and tried using it. While I
can compile it just fine, running it results in an unexpected element
error calling the (C#) webservice (or rather interpreting the result).
The field that causes problems is a boolean. It is completely left out
of the autogenerated code, except in the model class itself.
Small extract from the WSDL. Field in bold is the problem:
<xs:schema elementFormDefault="qualified"
targetNamespace="http://schemas.datacontract.org/2004/07/MyProject.Service.Models"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://schemas.datacontract.org/2004/07/MyProject.Service.Models">
<xs:complexType name="PersonInformationDTO">
<xs:sequence>
<xs:element minOccurs="0"
name="GeneralPractitioner" nillable="true"
type="tns:GeneralPractitionerDTO"/>
*<xs:element minOccurs="0"
name="PersonInformationProtected" type="xs:boolean"/>*
<xs:element minOccurs="0"
name="PersonName" nillable="true" type="tns:PersonNameDTO"/>
The SOAP response (small extract):
<LookupResult
xmlns:a="http://schemas.datacontract.org/2004/07/MyProject.Service.Models"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:GeneralPractitioner>
... valid content ...
</a:GeneralPractitioner>
*<a:PersonInformationProtected>false</a:PersonInformationProtected>*
<a:PersonName>
... valid content ...
</a:PersonName>
The PersonInformationDTO class has all relevant fields, but
PersonInformationProtected is typed as Boolean and the rest are JAXBElement:
public class PersonInformationDTO {
@XmlElementRef(name = "GeneralPractitioner", namespace =
"http://schemas.datacontract.org/2004/07/MyProject.Service.Models", type
= JAXBElement.class, required = false)
protected JAXBElement<GeneralPractitionerDTO> generalPractitioner;
@XmlElement(name = "PersonInformationProtected")
* protected Boolean personInformationProtected;*
@XmlElementRef(name = "PersonName", namespace =
"http://schemas.datacontract.org/2004/07/MyProject.Service.Models", type
= JAXBElement.class, required = false)
protected JAXBElement<PersonNameDTO> personName;
ObjectFactory.class doesn't mention the field PersonInformationProtected.
The files are generated like this:
./apache-cxf-3.5.5/bin/wsdl2java -d generated -p com.myproject -client
'http://url/somewhere?singleWsdl'
The error when running it:
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected
element
(uri:"http://schemas.datacontract.org/2004/07/MyProject.Service.Models",
local:"PersonInformationProtected"). Expected elements are
<{http://schemas.datacontract.org/2004/07/MyProject.Service.Models}SocialSecurityNumber>,<{http://schemas.datacontract.org/2004/07/MyProject.Service.Models}PersonName>,*<{}PersonInformationProtected>*,<{http://schemas.datacontract.org/2004/07/MyProject.Service.Models}PostalAddress>,<{http://schemas.datacontract.org/2004/07/MyProject.Service.Models}PublicHealthInsurance>,<{http://schemas.datacontract.org/2004/07/MyProject.Service.Models}GeneralPractitioner>
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:931)
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:737)
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:168)
at
org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:109)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:829)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1726)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1592)
at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1389)
at
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at
org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:689)
at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:528)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:439)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:354)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:312)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
at com.sun.proxy.$Proxy41.lookup(Unknown Source)
...
I hope someone can make sense of this. It may be something simple, but I
am somewhat stuck.
/Bernhard