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.
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 have xml with a tag name that contains '&' like D&G .
This xml is being validated against a XSD that has element definition for nm as below
<xs:element maxOccurs="1" minOccurs="0" name="nm" type="Max70Text"/>
<xs:simpleType name="Max70Text">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="70"/>
</xs:restriction>
</xs:simpleType>
in the code
....
InputStream is = new FileInputStream(l_file);
InputStreamReader isr = new InputStreamReader(is,"UTF-8");
Source source = new StreamSource(isr);
schemaValidator.validate(source);
...
i get SAX Error after the validate method is executed. How can i avoid this exception and make ampersand skip the validation.
Thanks in advance.
According to "Extensible Markup Language (XML) 1.1" (http://www.w3.org/TR/xml11/#NT-Name) '&' character is not a valid character for the element name.
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)]
I have the following type in wsdl (it is generated by third party tool):
<xsd:complexType name="IntArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
Sometimes Visual Studio generates:
public class IntArray : System.Collections.Generic.List<int> {}
And sometimes it doesn't generate any proxy type for this wsdl and just uses int[].
Collection type in Web Service configuration is System.Array.
What could be the reason for such upredictable behavior?
Edited:
I found the way how I can reproduce this behavior.
For examle we have two types:
<xsd:complexType name="IntArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="StringArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
VS generates:
public class IntArray : System.Collections.Generic.List<int> {}
public class StringArray : System.Collections.Generic.List<string> {}
Now I change StringArray type:
<xsd:complexType name="StringArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:string" />
<xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xsd:sequence>
<xsd:anyAttribute namespace="##any" processContents="lax"/>
</xsd:complexType>
VS generates proxy type for StringArray only. But not for IntArray.
Edited:
Reference.svcmap:
<ClientOptions>
<GenerateAsynchronousMethods>false</GenerateAsynchronousMethods>
<EnableDataBinding>true</EnableDataBinding>
<ExcludedTypes />
<ImportXmlTypes>false</ImportXmlTypes>
<GenerateInternalTypes>false</GenerateInternalTypes>
<GenerateMessageContracts>false</GenerateMessageContracts>
<NamespaceMappings />
<CollectionMappings />
<GenerateSerializableTypes>true</GenerateSerializableTypes>
<Serializer>Auto</Serializer>
<ReferenceAllAssemblies>true</ReferenceAllAssemblies>
<ReferencedAssemblies />
<ReferencedDataContractTypes />
<ServiceContractMappings />
</ClientOptions>
If you view all files for the project and then view the file called Reference.svcmap for the appropriate service reference could you please let me know what the following config options are in the xml?
<ExcludedTypes />
<ImportXmlTypes>false</ImportXmlTypes>
<GenerateInternalTypes>false</GenerateInternalTypes>
<GenerateSerializableTypes>false</GenerateSerializableTypes>
<Serializer>Auto</Serializer>
Sorry about putting it in as an answer but it was horribly unreadable in the comments.
Edit
Ok, so what is happening here is following:
You are using auto for the serializer.
The default is DataContractSerializer
When generating the proxy code, there is a check for forbidden xsd elements.
If forbidden elements are found, the XmlSerializer is used.
In your case, adding the xsd:any element is causing the serialization mode to change. If you want consistent serialization, you will have to remove the forbidden element or force the proxy generation to use XmlSerialization all the time.
Here is a link about the allowable schema elements for the DataContractSerializer.
Cheers
-Leigh
As far as I know, proxy classes are generated by SvcUtil.exe why do not you look at it with reflector...