I'm attempting to call a REST endpoint that returns JSON for a validated civic address. On a successful call, I get back something like this:
{
"success":true,
"results":[
{
"civicnumberid":123456,
"civic_address_as_string":"123 Main Street, My City, My Municipality, My County",
"esri_point":{
"x":12345.678,
"y":54321.012
}
}
],
"error":null
}
However if I send a request in a format that the service can't handle, I back back something like this:
{
"success":false,
"results":null,
"error":{
"code":123,
"message":"Invalid Civic Address. Valid Example: 123 Main St, My City...",
"details":[
"The civic address submitted to the service contained an alphabetic character where a number was expected."
]
}
}
Note the "results": null. While attempting to convert the response using JAX-RS 2.0 and Jackson 2.5.1:
ResponseObject response = client.target(url)
.path(REST_REQUEST_CONTEXT)
.queryParam("search_str", searchAddress)
.request(MediaType.APPLICATION_JSON)
.get(ResponseObject.class);
... it fails with "Error reading entity from input stream." Here's my current ObjectMapper setup:
defaultObjectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true)
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true)
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
My ResponseObject is a JAXB object:
public class ResponseObject
implements Serializable
{
private final static long serialVersionUID = 1L;
protected Boolean success;
#XmlElement(nillable = true)
protected List<Result> results;
#XmlElement(nillable = true)
protected Error error;
Can "results": null be handled gracefully or should I work with the service provider to return an empty list?
I was wrong in assuming that the null results was the issue. The Error jaxb type was defined using the following schema type:
<xs:complexType name="Error">
<xs:sequence>
<xs:element minOccurs="0" name="code" type="xs:int" />
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="details" nillable="true"
type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
</xs:sequence>
</xs:complexType>
... which resulted in the following JAXB type:
public class Error {
protected Integer code;
#XmlElement(nillable = true)
protected String message;
#XmlElement(nillable = true)
protected ArrayOfstring details;
But when I changed the schema to this:
<xs:complexType name="Error">
<xs:sequence>
<xs:element minOccurs="0" name="code" type="xs:int" />
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string" />
<!--
<xs:element minOccurs="0" name="details" nillable="true"
type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
-->
<xs:element minOccurs="0" name="details" maxOccurs="unbounded" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
... The following JAXB type works:
public class Error {
private final static long serialVersionUID = 1L;
protected Integer code;
#XmlElement(nillable = true)
protected String message;
#XmlElement(nillable = true)
protected List<String> details;
Related
I have an XSD and an XML file. Eclipse (version 4.7.3) validates these files with no errors or warnings (and, yes, Eclipse is validating the XML against the XSD). However, when I hand the XSD and the XML files to Xerces (with my XercesDOMParser validation set to Always), I get this error:
no declaration found for element 'g:tssConnections'
I have searched all over, and I cannot seem to find anything that is relevant. Can anyone tell me my error? Here is the XSD:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://gecoinc.com"
xmlns:geco="http://gecoinc.com"
elementFormDefault="qualified"
attributeFormDefault="qualified">
<xs:simpleType name="ipAddrType">
<xs:annotation>
<xs:documentation>
This type is used to create tags that contain a single
IPv4 address. This type may used for both multicast
and unicast addresses.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="([0-9]*\.){3}[0-9]*"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ipPortType">
<xs:annotation>
<xs:documentation>
This type is used to create tags that contain TCP or UDP port
numbers.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:unsignedShort">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="65535"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="serverType">
<xs:annotation>
<xs:documentation>
This type is used to create variables that hold information
needed to create a server endpoint.
</xs:documentation>
</xs:annotation>
<xs:all>
<xs:element name="remotePeerPort" type="geco:ipPortType" />
</xs:all>
</xs:complexType>
<xs:complexType name="clientType">
<xs:annotation>
<xs:documentation>
This type is used to create variables that hold information
needed to create a client endpoint.
</xs:documentation>
</xs:annotation>
<xs:all>
<xs:element name="remotePeerIp" type="geco:ipAddrType" />
<xs:element name="remotePeerPort" type="geco:ipPortType" />
</xs:all>
</xs:complexType>
<xs:complexType name="endpointType">
<xs:annotation>
<xs:documentation>
This type is used to create variables that hold information
needed to create an endpoint. Either a client or a server may
be created.
</xs:documentation>
</xs:annotation>
<xs:choice>
<xs:element name="serverParams" type="geco:serverType"/>
<xs:element name="clientParams" type="geco:clientType"/>
</xs:choice>
</xs:complexType>
<xs:simpleType name="transportType">
<xs:restriction base="xs:string">
<xs:enumeration value="tcp"/>
<xs:enumeration value="udp"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="connectionType">
<xs:annotation>
<xs:documentation>
This type is used to create structures that hold all of the
information that is needed for a single connection
</xs:documentation>
</xs:annotation>
<xs:all>
<xs:element name="isServer" type="xs:boolean"/>
<xs:element name="endpointParams" type="geco:endpointType"/>
<xs:element name="connectionName" type="xs:string"/>
<xs:element name="transport" type="geco:transportType"/>
<xs:element
name="multicastIntfAddr"
type="geco:ipAddrType"
minOccurs="0"
maxOccurs="1"/>
</xs:all>
</xs:complexType>
<xs:complexType name="connectionListType">
<xs:annotation>
<xs:documentation>
This type is used to create a list of connections.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element
name="connection"
type="geco:connectionType"
minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="tssConnections" type="geco:connectionListType" />
</xs:schema>
And here is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<g:tssConnections
xmlns:g="http://gecoinc.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://gecoinc.com oss.xsd">
<g:connection>
<g:connectionName>CM_LOAD_PRESET_OUT</g:connectionName>
<g:isServer>false</g:isServer>
<g:endpointParams>
<g:clientParams>
<g:remotePeerIp>224.5.5.5</g:remotePeerIp>
<g:remotePeerPort>11101</g:remotePeerPort>
</g:clientParams>
</g:endpointParams>
<g:transport>udp</g:transport>
<g:multicastIntfAddr>10.0.2.15</g:multicastIntfAddr>
</g:connection>
</g:tssConnections>
Thanks very much in advance!
I found the answer to this problem. It turns out that the error message coming out of Xerces was very misleading. I had to turn on several aspects of validation in the parser, as follows:
domParser->setDoNamespaces( true );
domParser->setDoSchema( true );
domParser->setHandleMultipleImports ( true );
domParser->setValidationSchemaFullChecking( true );
Once I did that, the error went away. I hope that the above can help someone.
I am using eclipse link(v2.5.1) Dynamic JAXB to convert XML to JSON and viceversa using a multiple schemas. While umarshalling the JSON to XML,I want to validate the JSON(against the XSD) and Dynamic Moxy is unable to validate the generated JSON and results in classcast exception.
emp.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:emp="Employee:2:0" targetNamespace="Employee:2:0"
elementFormDefault="unqualified" attributeFormDefault="unqualified"
version="2.0">
<xsd:element name="searchManager" type="emp:SearchManager" />
<xsd:complexType name="SearchManager">
<xsd:sequence>
<xsd:element name="CompanyName" type="xsd:string" />
<xsd:element name="objects" type="emp:Employee" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Employee">
<xsd:complexContent>
<xsd:extension base="emp:Organization">
<xsd:sequence>
<xsd:element name="EmpId" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="Projects">
<xsd:complexContent>
<xsd:extension base="emp:Organization"/>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="Organization">
<xsd:annotation>
<xsd:documentation>Abstract base class </xsd:documentation>
</xsd:annotation>
</xsd:complexType>
</xsd:schema>
Manager.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="Manager:1:0" xmlns:emp="Employee:2:0"
xmlns:manager="Manager:1:0" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified" attributeFormDefault="unqualified"
version="1.0">
<!-- schema imports -->
<xs:import namespace="Employee:2:0" schemaLocation="emp.xsd" />
<xs:complexType name="Manager">
<xs:annotation>
<xs:documentation>
Definition of class Employee
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="emp:Employee">
<xs:sequence>
<xs:element name="teamSize" type="xsd:int" minOccurs="0" />
<xs:element name="project1" type="manager:Project1"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Project1">
<xs:complexContent>
<xs:extension base="manager:Developement">
<xs:sequence>
<xs:element name="type" type="xsd:int" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Developement">
<xs:annotation>
<xs:documentation>
Abstract base class for an Development
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="emp:Projects"/>
</xs:complexContent>
</xs:complexType>
</xs:schema>
sample.xml
<emp:searchManager xmlns:emp="Employee:2:0"
xmlns:manager="Manager:1:0">
<CompanyName>Test</CompanyName>
<objects xmlns:ns2="Manager:1:0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:Manager">
<EmpId>123456</EmpId>
<teamSize>10</teamSize>
<project1>
<type>1</type>
</project1>
</objects>
</emp:searchManager>
The driver program to test is as follows
public class XMLToJSON {
/**
* #param args
*/
public static void main(String[] args) {
FileInputStream xsdInputStream;
try {
xsdInputStream = new FileInputStream("Manager.xsd");
DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(xsdInputStream, new MyEntityResolver(), null, null);
FileInputStream xmlInputStream = new FileInputStream("sample.xml");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement<DynamicEntity> manager = (JAXBElement) unmarshaller.unmarshal(xmlInputStream);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
//input xml to print
marshaller.marshal(manager, System.out);
Map namespaces = new HashMap();
namespaces.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
namespaces.put("Employee:2:0", "ns1");
namespaces.put("Manager:1:0", "ns2");
// XML to JSON
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, namespaces);
FileOutputStream jsonOutputStream = new FileOutputStream("sample.json");
marshaller.marshal(manager, jsonOutputStream);
marshaller.marshal(manager, System.out);
//JSON to XML
JAXBUnmarshaller jsonUnmarshaller = jaxbContext.createUnmarshaller();
jsonUnmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
jsonUnmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER, namespaces);
jsonUnmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, true);
jsonUnmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX, "#");
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File("Manager.xsd"));
jsonUnmarshaller.setSchema(schema);
StreamSource json = new StreamSource("sample.json");
JAXBElement<DynamicEntity> myroot = (JAXBElement) jsonUnmarshaller.unmarshal(json);
Marshaller m = jaxbContext.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
m.marshal(myroot, System.out);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JAXBException e) {
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Generated Sample JSON
{
"ns1.searchManager" : {
"CompanyName" : "Test",
"objects" : [ {
"xsi.type" : "ns2.Manager",
"EmpId" : "123456",
"teamSize" : 10,
"project1" : [ {
"type" : 1
} ]
} ]
}
}
While unmarshalling the below exception was seen
Exception in thread "main" java.lang.ClassCastException: org.eclipse.persistence.internal.oxm.record.XMLReaderAdapter$ExtendedContentHandlerAdapter cannot be cast to org.eclipse.persistence.internal.oxm.record.UnmarshalRecord
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.isTextValue(JSONReader.java:454)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:350)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:244)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:430)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:299)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parseRoot(JSONReader.java:166)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:125)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:140)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:778)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:666)
at org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:593)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:287)
at XMLToJSON.main(XMLToJSON.java:74)
EDIT:Corrected the generated sample json
Question
The intention is to check whether JSON conforms to the XML schema. Does Dynamic JAXB support JSON Validation while unmarshalling? Is this a bug in Dynamic JAXB Moxy?
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
You are hitting the following issue which was fixed in the 2.5.1 (and 2.6.0) streams.
http://bugs.eclipse.org/407498
The fix is available in EclipseLink 2.5.1 (and 2.6.0) in the nightly builds starting September 11, 2013 from the following link:
http://www.eclipse.org/eclipselink/downloads/nightly.php
Schema Validation and JSON Unmarshalling
Due to how we need to process the JSON document, validating the JSON input against an XML schema is not guaranteed to work. Below is the exception you will get for your use case once you get the ClassCastException fix.
javax.xml.bind.UnmarshalException
- with linked exception:
[Exception [EclipseLink-25004] (Eclipse Persistence Services - #VERSION#.#QUALIFIER#): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred unmarshalling the document
Internal Exception: org.xml.sax.SAXParseException; cvc-complex-type.2.4.d: Invalid content was found starting with element 'teamSize'. No child element is expected at this point.]
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:980)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:290)
at forum18824990.XMLToJSON.main(XMLToJSON.java:63)
Caused by: Exception [EclipseLink-25004] (Eclipse Persistence Services - #VERSION#.#QUALIFIER#): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred unmarshalling the document
Internal Exception: org.xml.sax.SAXParseException; cvc-complex-type.2.4.d: Invalid content was found starting with element 'teamSize'. No child element is expected at this point.
at org.eclipse.persistence.exceptions.XMLMarshalException.unmarshalException(XMLMarshalException.java:115)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:144)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:784)
at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:666)
at org.eclipse.persistence.internal.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:566)
at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:287)
... 1 more
Caused by: org.xml.sax.SAXParseException; cvc-complex-type.2.4.d: Invalid content was found starting with element 'teamSize'. No child element is expected at this point.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:453)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3232)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1795)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:741)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:565)
at org.eclipse.persistence.internal.oxm.record.XMLReader$ValidatingContentHandler.startElement(XMLReader.java:431)
at org.eclipse.persistence.internal.oxm.record.XMLReaderAdapter$ExtendedContentHandlerAdapter.startElement(XMLReaderAdapter.java:178)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:302)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:436)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:418)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:244)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:436)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:303)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parseRoot(JSONReader.java:166)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:125)
at org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:140)
... 5 more
I created a Web Reference (also tried Service Reference) to a WSDL that had the following node inside an xsd:
<xs:element name="filter">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element minOccurs="0" maxOccurs="unbounded" ref="condition" />
<xs:element minOccurs="0" maxOccurs="unbounded" ref="filter" />
</xs:choice>
<xs:attribute default="and" name="type">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="and" />
<xs:enumeration value="or" />
<xs:enumeration value="AND" />
<xs:enumeration value="OR" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute default="false" name="not" type="xs:boolean" />
</xs:complexType>
</xs:element>
When the client proxy class is created it produces this:
'''<remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225"), _
System.SerializableAttribute(), _
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, [Namespace]:="urn://wsc.acme.com/dm/2010/02/02")> _
Public Enum filterType
'''<remarks/>
[and]
'''<remarks/>
[or]
'''<remarks/>
[AND]
'''<remarks/>
[OR]
End Enum
This wouldn't build in a VB project because VB.NET is case insensitive. I tried deleting one set of and/or, but when the XML is created, it simply ignores the selected value. I also tried appending an X at the end of one the sets which also failed.
Is there a way to make this work? I also tried updating the XSD so it just had two values without success. The interesting thing to note is that default is set to "and" and while debugging it will set it to and, it doesn't actually produce the node attribute of it just generates .
You simply cannot have two enums with the same name. You can try setting the AllowMultiple attribute but the problem you are experiencing will still happen. My suggestion would be to remove the duplicate values in the original XSD and rebuild.
I need to create a DataSet.xsd file according to a NHibernate.hbm.xml file or a Class File. These are Mapping files and class files than we use to work with our DB.
You may ask me, why I do need a DataSet file, generating from a Nhibernate.hbm.xml file or a .cs file?
It's because we're using Crystal Reports, and we're using Frameworks, MVVM, INotifyPropertyChanged, NHibernate and after a lot of studying, for our case, would be better if we Convert an object while in executing time of program and use it to generate a report. If this tool exists, it will make easier, 'cause we have over 60, 70 columns per table in our DB. Since we're already with all these components working into our Project, it wouldn't make sense if we start to use sql queries to generate reports.
This tool, or 'the way to' create this DataSet file, need to read those file in these formats:
Nhibernate.hbm.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="PCT.Domain" namespace="Gerdau.PCT.Kernel.Domain">
<class name="Furnace" table="Furnace" lazy="false">
<id name="Id" column="Id_Furnace" type="Int64">
<generator class="Geraes.GLib.GDomainBasis.CustomTableHiLoGenerator, GLib.GDomainBasis" />
</id>
<property name="Name" column="Name" type="String" length="50" not-null="true"/>
<property name="Code" column="Code" type="Char" not-null="true"/>
<property name="Mill" column="Mill" type="String" length="2" not-null="true"/>
<property name="DischEnabled" column="Disch_Enabled" type="Char" not-null="true"/>
<property name="DischEnabledTemp" column="Disch_Enabled_Temp" type="Char" not-null="true"/>
<property name="ChargeEnabled" column="Charge_Enabled" type="Char" not-null="true"/>
<property name="ChargeEnabledTemp" column="Charge_Enabled_Temp" type="Char" not-null="true"/>
</class>
</hibernate-mapping>
CSharp .cs File:
public class Furnace : BaseEntity
{
public virtual String Name { get; set; }
public virtual Char Code { get; set; }
public virtual String Mill { get; set; }
public virtual Char DischEnabled { get; set; }
public virtual Boolean DischEnabledConv
{
get
{
return DischEnabled.ConvertYesNoToBoolean();
}
set
{
DischEnabled = ((Boolean)value).ConvertYesNoToBoolean();
}
}
public virtual Boolean DischEnabledTempConv
{
get
{
return DischEnabledTemp.ConvertYesNoToBoolean();
}
set
{
DischEnabledTemp = ((Boolean)value).ConvertYesNoToBoolean();
}
}
public virtual Char DischEnabledTemp { get; set; }
public virtual Char ChargeEnabled { get; set; }
public virtual Boolean ChargeEnabledConv
{
get
{
return ChargeEnabled.ConvertYesNoToBoolean();
}
set
{
ChargeEnabled = ((Boolean)value).ConvertYesNoToBoolean();
}
}
public virtual Boolean ChargeEnabledTempConv
{
get
{
return ChargeEnabledTemp.ConvertYesNoToBoolean();
}
set
{
ChargeEnabledTemp = ((Boolean)value).ConvertYesNoToBoolean();
}
}
public virtual Char ChargeEnabledTemp { get; set; }
public virtual ConfiguracaoForno MillConv
{
get
{
if (Mill == ConfiguracaoForno.SM.ToString())
return ConfiguracaoForno.SM;
if (Mill == ConfiguracaoForno.PM.ToString())
return ConfiguracaoForno.PM;
else
return ConfiguracaoForno.NN;
}
}
public override String ToString()
{
return "Forno " + Code + " (" + Name + "): Laminador " + MillConv;
}
}
I know it's an very specific case, but if you can show to us at least a way, it'll be of great help.
Best regards,
Gustavo
Edit:
Found a way to do it: using XSD.EXE, a internal Tool from Visual Studio, i've extracted the mapping from my assembly:
C:\>xsd / c /l:CS -t:Furnace <MyAssembly>.dll -o:"D:\Temp"
But now, when I do this:
D:\>xsd /c schema0.xsd
Results in these errors:
D:\Temp>xsd /c schema0.xsd
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: Type 'char' is not declared, or is not a simple type.
Line 21, position 5.
Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 10, position 7.
Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 12, position 7.
Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 15, position 7.
Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 16, position 7.
Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 19, position 7.
Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
Error: Error generating classes for schema 'schema0'.
- The datatype 'char' is missing.
If you would like more help, please type "xsd /?".
Here's my generated schema.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://microsoft.com/wsdl/types/" />
<xs:element name="Furnace" nillable="true" type="Furnace" />
<xs:complexType name="Furnace">
<xs:complexContent mixed="false">
<xs:extension base="BaseEntity">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
<xs:element minOccurs="1" maxOccurs="1" name="Code" xmlns:q1="http://microsoft.com/wsdl/types/" type="q1:char" />
<xs:element minOccurs="0" maxOccurs="1" name="Mill" type="xs:string" />
<xs:element minOccurs="1" maxOccurs="1" name="DischEnabled" xmlns:q2="http://microsoft.com/wsdl/types/" type="q2:char" />
<xs:element minOccurs="1" maxOccurs="1" name="DischEnabledConv" type="xs:boolean" />
<xs:element minOccurs="1" maxOccurs="1" name="DischEnabledTempConv" type="xs:boolean" />
<xs:element minOccurs="1" maxOccurs="1" name="DischEnabledTemp" xmlns:q3="http://microsoft.com/wsdl/types/" type="q3:char" />
<xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabled" xmlns:q4="http://microsoft.com/wsdl/types/" type="q4:char" />
<xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabledConv" type="xs:boolean" />
<xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabledTempConv" type="xs:boolean" />
<xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabledTemp" xmlns:q5="http://microsoft.com/wsdl/types/" type="q5:char" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="BaseEntity">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="Id" type="xs:long" />
</xs:sequence>
</xs:complexType>
</xs:schema>
I appreciate for any help.
Gustavo
You're missing an XSD file.
UPDATE: Let's assume you're staying with xsd.exe. In this case, modify the import statement as following (I call this file XSD-1.xsd):
<xs:import namespace="http://microsoft.com/wsdl/types/" schemaLocation="XSD-2.xsd" />
Copy the content below in XSD-2.xsd file, in the same folder:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://microsoft.com/wsdl/types/" elementFormDefault="qualified" targetNamespace="http://microsoft.com/wsdl/types/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="char">
<xs:restriction base="xs:unsignedShort" />
</xs:simpleType>
</xs:schema>
Run the xsd.exe with the following line:
xsd XSD-1.xsd /c
You should get an XSD-1.cs file and some warnings
If you want to use svcutil, you must have the XSD-2.xsd, otherwise it won't work; also, on the plus side you don't have to modify the XSD-1.xsd:
svcutil XSD-1.xsd XSD-2.xsd /dconly
It works fine, without any errors. I am running v4.
I'm using Visual Studio 2008 to write a simple web-service but have been running into some problems. You might need to format my
The full expected message is something along the lines of:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace = "http://www.website.com/WS/"
elementFormDefault = "qualified"
xmlns = "http://www.website.com/WS/"
xmlns:xs = "http://www.w3.org/2001/XMLSchema"
>
<xs:element name="QUERYFOOTBALL">
<xs:complexType>
<xs:sequence>
<xs:element name="KEY" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="FOOTBALL">
<xs:complexType>
<xs:sequence>
<xs:element name="HEADER" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="TEAM_ID" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="MATCH_ID" minOccurs="1" maxOccurs="1" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GAME" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="ONE" minOccurs="1" maxOccurs="1" type="xs:string" />
<xs:element name="TWO" minOccurs="1" maxOccurs="1" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
However when I generate the service the SOAP message layout/call appears like so
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<QueryFootball xmlns="http://www.website.com/WS/">
<QUERYFOOTBALL>
<KEY>string</KEY>
<FOOTBALL>
<HEADER>
<TEAM_ID>string</TEAM_ID>
<MATCH_ID>string</MATCH_ID>
</HEADER>
<GAME>
<ONE>string</ONE>
<TWO>string</TWO>
</GAME>
</FOOTBALL>
</QUERYFOOTBALL>
</QueryFootball>
</soap:Body>
</soap:Envelope>
My actual C# code looks like this:
namespace FootballSimulator
{
[System.ServiceModel.ServiceBehaviorAttribute(InstanceContextMode=System.ServiceModel.InstanceContextMode.PerCall, ConcurrencyMode=System.ServiceModel.ConcurrencyMode.Single)]
public class FootballSimulator : IFootballSimulator
{
public virtual QUERYFOOTBALLRESPONSE QUERYFOOTBALL(QUERYFOOTBALL request)
{
throw new System.NotImplementedException();
}
}
}
I guess my question is how can I edit the Schema/WSCFBlue so that it doesn't force that extra in the SOAP request?
I would really appreciated any advice/guidance you could give. I can give you an outline to what I did:
In visual studio I right clicked my 2 schemas (request and response message) and selected WSCFblue then Create WSDL Interface Description
I selected the correct schemas/ports and gave them message in a name of QUERYFOOTBALL and the message out a name of QUERYFOOTBALLRESPONSE
I right clicked the WSDL that was generated in above steps and went selected WSCFblue then Generate Data Contract Code (which is does and gives me my objects QUERYFOOTBALL and QUERYFOOTBALLRESPONSE)
I right clicked the WSDL and selected WSCFblue then Generate Web Service Code
If there is anything obvious that I am doing wrong I would really appreciated it if you can show me what it is. It looks asthough the method name is the causing the additional tag to be added around the expected soap message. In my schema after QUERYFOOTBALL element is another element called KEY, this is the reason I cannot just take out QUERYFOOTBALL and create an object called "FOOTBALL".
What I want the web-service to accept is this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<QUERYFOOTBALL>
<KEY>string</KEY>
<FOOTBALL>
<HEADER>
<TEAM_ID>string</TEAM_ID>
<MATCH_ID>string</MATCH_ID>
</HEADER>
<GAME>
<ONE>string</ONE>
<TWO>string</TWO>
</GAME>
</FOOTBALL>
</QUERYFOOTBALL>
</soap:Body>
</soap:Envelope>
Really appreciate any help you can give, look forward to hearing your experiences/opinions/advice
Better late than never....
Try adding this to your Web Method:
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]