-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from DigDes/develop
Merge 1.0.0.2-alpha
- Loading branch information
Showing
12 changed files
with
441 additions
and
43 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/SoapCore.Tests/Wsdl/Services/ICollectionDataContractService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using System.ServiceModel; | ||
|
||
namespace SoapCore.Tests.Wsdl.Services | ||
{ | ||
[ServiceContract] | ||
public interface ICollectionDataContractService | ||
{ | ||
[OperationContract] | ||
CollectionDataContractService.MyList<string> ListStrings(); | ||
|
||
[OperationContract] | ||
CollectionDataContractService.MyList<CollectionDataContractService.MyType> ListMyTypes(); | ||
} | ||
|
||
public class CollectionDataContractService : ICollectionDataContractService | ||
{ | ||
public MyList<string> ListStrings() => throw new NotImplementedException(); | ||
public MyList<MyType> ListMyTypes() => throw new NotImplementedException(); | ||
|
||
[CollectionDataContract(Namespace = "http://testnamespace.org", Name = "My{0}List", ItemName = "MyItem")] | ||
public class MyList<T> : List<T> | ||
{ | ||
} | ||
|
||
public class MyType | ||
{ | ||
public string MyProperty { get; set; } | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/SoapCore.Tests/Wsdl/Services/IDatetimeOffsetService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.ServiceModel; | ||
|
||
namespace SoapCore.Tests.Wsdl.Services | ||
{ | ||
[ServiceContract] | ||
public interface IDatetimeOffsetService | ||
{ | ||
[OperationContract] | ||
DateTimeOffset Method(DateTimeOffset model); | ||
} | ||
|
||
public class DateTimeOffsetService : IDatetimeOffsetService | ||
{ | ||
public DateTimeOffset Method(DateTimeOffset model) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/SoapCore.Tests/Wsdl/Services/ITestMultipleTypesService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Data; | ||
using System.ServiceModel; | ||
using System.Xml.Linq; | ||
|
||
namespace SoapCore.Tests.Wsdl.Services | ||
{ | ||
[ServiceContract] | ||
public interface ITestMultipleTypesService | ||
{ | ||
[OperationContract] | ||
DataTable GetDataTable(DataTable input); | ||
|
||
[OperationContract] | ||
System.Xml.Linq.XElement GetXElement(System.Xml.Linq.XElement input); | ||
|
||
[OperationContract] | ||
DateTimeOffset GetDateTimeOffset(DateTimeOffset input); | ||
|
||
[OperationContract] | ||
string GetString(string input); | ||
|
||
[OperationContract] | ||
MyClass GetMyClass(MyClass input); | ||
} | ||
|
||
public class TestMultipleTypesService : ITestMultipleTypesService | ||
{ | ||
public DataTable GetDataTable(DataTable input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public DateTimeOffset GetDateTimeOffset(DateTimeOffset input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public string GetString(string input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public XElement GetXElement(XElement input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public MyClass GetMyClass(MyClass input) | ||
{ | ||
return input; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/SoapCore.Tests/Wsdl/Services/IXmlSchemaProviderTypeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Data; | ||
using System.ServiceModel; | ||
using System.Xml.Linq; | ||
|
||
namespace SoapCore.Tests.Wsdl.Services | ||
{ | ||
[ServiceContract] | ||
public interface IXmlSchemaProviderTypeService | ||
{ | ||
[OperationContract] | ||
DataTable GetDataTable(DataTable input); | ||
|
||
[OperationContract] | ||
System.Xml.Linq.XElement GetXElement(System.Xml.Linq.XElement input); | ||
} | ||
|
||
public class XmlSchemaProviderTypeService : IXmlSchemaProviderTypeService | ||
{ | ||
public DataTable GetDataTable(DataTable input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public XElement GetXElement(XElement input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Data; | ||
using System.ServiceModel; | ||
using System.Xml.Linq; | ||
|
||
namespace SoapCore.Tests.Wsdl.Services | ||
{ | ||
public class MyClass | ||
{ | ||
public string StringProperty { get; set; } | ||
public int IntProperty { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Xml; | ||
using System.Xml.Schema; | ||
using System.Xml.Serialization; | ||
|
||
namespace SoapCore.Meta | ||
{ | ||
public static class BodyWriterExtensions | ||
{ | ||
//switches to easily revert to previous behaviour if there is a problem | ||
private static bool useXmlSchemaProvider = true; | ||
private static bool useXmlReflectionImporter = false; | ||
public static bool TryAddSchemaTypeFromXmlSchemaProviderAttribute(this XmlDictionaryWriter writer, Type type, string name, SoapSerializer serializer) | ||
{ | ||
if (!useXmlSchemaProvider && !useXmlReflectionImporter) | ||
{ | ||
return false; | ||
} | ||
|
||
if (useXmlReflectionImporter) | ||
{ | ||
var schemas = new XmlSchemas(); | ||
var xmlImporter = new XmlReflectionImporter(); | ||
var exporter = new XmlSchemaExporter(schemas); | ||
|
||
var xmlTypeMapping = xmlImporter.ImportTypeMapping(type, new XmlRootAttribute() { ElementName = name }); | ||
exporter.ExportTypeMapping(xmlTypeMapping); | ||
schemas.Compile(null, true); | ||
|
||
var memoryStream = new MemoryStream(); | ||
foreach (XmlSchema schema in schemas) | ||
{ | ||
schema.Write(memoryStream); | ||
} | ||
memoryStream.Position = 0; | ||
|
||
var streamReader = new StreamReader(memoryStream); | ||
var result = streamReader.ReadToEnd(); | ||
|
||
var doc = new XmlDocument(); | ||
doc.LoadXml(result); | ||
doc.DocumentElement.WriteContentTo(writer); | ||
|
||
return true; | ||
} | ||
|
||
var xmlSchemaSet = new XmlSchemaSet(); | ||
var xmlSchemaProviderAttribute = type.GetCustomAttribute<XmlSchemaProviderAttribute>(true); | ||
if (xmlSchemaProviderAttribute != null && true) | ||
{ | ||
XmlSchema schema = new XmlSchema(); | ||
if (xmlSchemaProviderAttribute.IsAny) | ||
{ | ||
//MetaWCFBodyWriter usage.... | ||
//writer.WriteAttributeString("name", name); | ||
//writer.WriteAttributeString("nillable", "true"); | ||
//writer.WriteStartElement("xs", "complexType", Namespaces.XMLNS_XSD); | ||
//writer.WriteStartElement("xs", "sequence", Namespaces.XMLNS_XSD); | ||
//writer.WriteStartElement("xs", "any", Namespaces.XMLNS_XSD); | ||
//writer.WriteAttributeString("minOccurs", "0"); | ||
//writer.WriteAttributeString("processContents", "lax"); | ||
//writer.WriteEndElement(); | ||
//writer.WriteEndElement(); | ||
//writer.WriteEndElement(); | ||
var sequence = new XmlSchemaSequence(); | ||
sequence.Items.Add(new XmlSchemaAny() { ProcessContents = XmlSchemaContentProcessing.Lax }); | ||
var complex = new XmlSchemaComplexType() | ||
{ | ||
Particle = sequence | ||
}; | ||
var element = new XmlSchemaElement() | ||
{ | ||
MinOccurs = 0, | ||
MaxOccurs = 1, | ||
Name = name, | ||
IsNillable = serializer == SoapSerializer.DataContractSerializer ? true : false, | ||
SchemaType = complex | ||
}; | ||
schema.Items.Add(element); | ||
} | ||
else | ||
{ | ||
var methodInfo = type.GetMethod(xmlSchemaProviderAttribute.MethodName, BindingFlags.Static | BindingFlags.Public); | ||
var xmlSchemaType = (XmlSchemaType)methodInfo.Invoke(null, new object[] { xmlSchemaSet }); | ||
var element = new XmlSchemaElement() | ||
{ | ||
MinOccurs = 0, | ||
MaxOccurs = 1, | ||
Name = name, | ||
SchemaType = xmlSchemaType | ||
}; | ||
schema.Items.Add(element); | ||
} | ||
|
||
var memoryStream = new MemoryStream(); | ||
schema.Write(memoryStream); | ||
memoryStream.Position = 0; | ||
|
||
var streamReader = new StreamReader(memoryStream); | ||
var result = streamReader.ReadToEnd(); | ||
|
||
var doc = new XmlDocument(); | ||
doc.LoadXml(result); | ||
doc.DocumentElement.WriteContentTo(writer); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.