I have created a simple Northwind's Product REST Web Service in WCF at /Northwind/Product. I have also enabled WCF Web HTTP Service Help Page on my service, which is at /Northwind/Product/help. I have a "GET" operation and its help page is located at: /Northwind/Product/help/operations/Get, which is your standard WCF help page that displays the Xml body, Json body, Xml Schema and Additional Xml Schemas. Pretty straight forward, right? Okay now, on to the fun stuff...
I am interested in the Xml Schema section, which is:
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Product">
<xs:sequence>
<xs:element minOccurs="0" name="CategoryID" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="Discontinued" type="xs:boolean" />
<xs:element minOccurs="0" name="ProductID" type="xs:int" />
<xs:element minOccurs="0" name="ProductName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="QuantityPerUnit" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="ReorderLevel" nillable="true" type="xs:short" />
<xs:element minOccurs="0" name="SupplierID" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="UnitPrice" nillable="true" type="xs:decimal" />
<xs:element minOccurs="0" name="UnitsInStock" nillable="true" type="xs:short" />
<xs:element minOccurs="0" name="UnitsOnOrder" nillable="true" type="xs:short" />
</xs:sequence>
</xs:complexType>
<xs:element name="Product" nillable="true" type="Product" />
</xs:schema>
I am interested in it because of the datatypes. I want to know the datatypes of the elements. Now, I understand that's not the fundamentals of REST. However, I don't want SOAP objects here. I want to keep my services simple and loosely typed and yet still be aware of their datatypes when needed.
My question is, how can I expose just this particular section of the help file? If I cannot do that, what are my other options for achieving what I am trying to do here?
Maybe you could try with OData, as I see it it is in between of REST and SOAP.
http://msdn.microsoft.com/es-es/library/cc668794.aspx
I do not think that it is possible to be both loosly typed and a the same time know the types behind the fields.
You could send everything as a string, and then throw an exception if conversion is not possible.
There does not appear to be a tag in the xs:element tag that could be used for help infomation, http://www.w3schools.com/schema/el_element.asp
Related
My Question is I have application HP Service Manager they have 2 different links to access wsdl file but wsdl file contain same data same everything.
how can i used wsdl's as service reference in C# application they import as reference but not create endpoint and binding in app.confg file because complexTyple same in both file how can Microsoft handle this issue.
<xs:complexType name="EventOutKeysType">
<xs:sequence>
<xs:element minOccurs="0" name="evsysseq" nillable="true"
type="cmn:StringType"/>
</xs:sequence>
<xs:attribute name="query" type="xs:string" use="optional"/>
<xs:attribute name="updatecounter" type="xs:long" use="optional"/>
</xs:complexType>
<xs:complexType name="EventOutInstanceType">
----------------
<xs:complexType name="EventOutKeysType">
<xs:sequence>
<xs:element minOccurs="0" name="evsysseq" nillable="true"
type="cmn:StringType"/>
</xs:sequence>
<xs:attribute name="query" type="xs:string" use="optional"/>
<xs:attribute name="updatecounter" type="xs:long" use="optional"/>
</xs:complexType>
<xs:complexType name="EventOutInstanceType">
you see they have different links but same xml,
like
..../SM/EventOut.wsdl
..../SM/EventManagement.wsdl
please advice
I am using NDbunit to unit test the functionality of my methods and database. For NDbunit to work, it firsts loads an xml schema file (.xsd) and then reads in the xml file with all the data that will be populated into the database. Here is my xml schema file MessageDS.xsd:
<xs:schema id="MessageDS"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
targetNamespace="http://tempuri.org/MessageDS.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/MessageDS.xsd"
xmlns:mstns="http://tempuri.org/MessageDS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="MessageDS" msdata:IsDataSet="true" msdata:UseCurrentLocalexmlns="true" msprop:Generator_MessageDSName="MessageDS" msprop:Generator_DataSetName="MessageDS">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="MESSAGE">
<xs:complexType>
<xs:sequence>
<xs:element name="CREATED_AT" type="xs:dateTime" />
<xs:element name="SUBJECT" type="xs:string" />
<xs:element name="MESSAGE" type="xs:string" />
<xs:element name="FROM" type="xs:string" />
<xs:element name="TO" type="xs:string" />
<xs:element name="TO_EMAIL" type="xs:string" />
<xs:element name="EMAIL_SENT_AT" type="xs:dateTime" />
</xs:sequence>
<xs:attribute name="ID" type="xs:int" use="required" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Here is my xml data file Message.xml:
<MessageDS xlmns="http://tempuri.org/MessageDS.xsd">
<MESSAGE ID="1">
<FROM>Test User 2</FROM>
<TO>Test User 1</TO>
<MESSAGE>
</MessageDS>
Initially I was just using the dll references for NDbunit but eventually I downloaded the source code and started debugging through the problems. I noticed that after the xml schema file is read in the xml file is not being properly loaded into the dataset (System.Data.DataSet). The only xml that is written in is:
<MessageDS xmlns="http://tempuri.org/MessageDS.xsd" />
For some reason my MESSAGE objects are not being read into the xml file. I'm not sure if this is because my xml file is not properly created according to the xml schema file or something else is the cause. I tried to follow the examples on the https://code.google.com/p/ndbunit/wiki/QuickStartGuide for NDbunit and I also looked at the xml files in the testing files for NDbunit.
To start with, "xlmns" is misspelled:
<MessageDS xlmns="http://tempuri.org/MessageDS.xsd">
I need to fix the error message below:
Error occured while validating xmlThe element 'UserFields' has invalid child element 'LastApproverID'. List of possible elements expected: 'FirtApproverID'.
Below is my xsd for validating the xml schema :
<xs:element name="UserFields" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FirtApproverID" type="xs:string" minOccurs="1" />
<xs:element name="LastApproverID" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
The order of the firstapproverid and lastapproverid does not matter but the tag need to occur atleast once.
i.e it can appear
<UserFields>
<LastApproverID>123</LastApproverID>
<FirtApproverID>456</FirtApproverID>
</UserFields>
OR
<UserFields>
<FirtApproverID>456</FirtApproverID>
<LastApproverID>123</LastApproverID>
</UserFields>
The <xs:all> indicator can solve your problem.
See here for answer
Please, improve your Google skills.
This is what my xsd looks like. Air and Car extend Segment.
<xs:element name="PNR" type="PNR" />
<xs:element minOccurs="0" maxOccurs="1" name="Segments" >
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Segment" type="Segment"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Air">
<xs:complexContent>
<xs:extension base="Segment">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Departure" type="AirportInfo" />
<xs:element minOccurs="0" maxOccurs="1" name="Arrival" type="AirportInfo" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Car">
<xs:complexContent>
<xs:extension base="Segment">
<xs:sequence>
<xs:element name="PickUp" type="AddressInfo" minOccurs="0" maxOccurs="1"/>
<xs:element name="DropOff" type="AddressInfo" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
I want an output that looks like this:
<Segments>
<Segment xsi:type="Air">
<Departure></Departure>
<Arrival></Arrival>
</Segment>
<Segment xsi:type="Car">
<PickUp></PickUp>
<DropOff></DropOff>
</Segment>
</Segments>
But when I auto-generate XML from my XSD using a tool such as xmlspy or a .net library (or whatever), I get this (Air generated multi times w/o Car).
<Segments>
<Segment xsi:type="Air">
<Departure></Departure>
<Arrival></Arrival>
</Segment>
<Segment xsi:type="Air">
<Departure></Departure>
<Arrival></Arrival>
</Segment>
</Segments>
Is there something wrong with my XSD?
Here's a technique I once used to generate XML from a set of schemas. Although it doesn't look like the right class for the job, take a look at the XmlSchemaValidator class. The trick is that you can ask it what is valid for the document you're validating at that point in the validation. You can then generate the XML that is valid at that point in the document, and validate the same XML, in order to update the XmlSchemaValidator. You can then ask it again what is valid at that point in the document, etc.
When you get to an abstract type, you'll have to know to generate one of each possible derived type.
I am trying to create an XML schema to use with the Web Service Software Factory. It's a fairly simple schema that is just a group of person objects. The (simplified) schema file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Persons" type="PersonsType" />
<xs:complexType name="PersonsType">
<xs:sequence>
<xs:element name="Person" type="PersonType" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="PersonType">
<xs:all>
<xs:element name="PersonName" type="xs:string" />
<xs:element name="PersonAge" type="xs:integer" />
</xs:all>
</xs:complexType>
</xs:schema>
It's a simple collection of person elements with a parent element called Persons.
When I try to validate my .serviceContract file I get the error 'The file name 'Persons.xsd' is not compliant with the DataContactSerializer'.
Does anybody know how to fix this schema so that it will work with the Web Service Software Factory? And for bonus points, the next structure that I have to worry about will be a recursive list of corporations. Any suggestions about how to make recursive schemas that work with WSSF would be appreciated as well.
Did you already try to avoid named types?
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Persons">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="PersonName" type="xs:string" />
<xs:element name="PersonAge" type="xs:integer" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Also you may try to change <xs:all> to <sequence> in your <Person>.