Skip to content

Commit

Permalink
Merge pull request #494 from DigDes/develop
Browse files Browse the repository at this point in the history
1.1.0.1-beta
  • Loading branch information
kotovaleksandr authored Jun 24, 2020
2 parents 52eb146 + c5e39c3 commit a161292
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 44 deletions.
45 changes: 27 additions & 18 deletions src/SoapCore/Meta/MetaBodyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ private void WriteParameters(XmlDictionaryWriter writer, SoapMethodParameterInfo
var typeRootName = string.IsNullOrWhiteSpace(xmlRootAttr?.ElementName) ? null : xmlRootAttr.ElementName;

var parameterName = elementName
?? parameterInfo.Parameter.GetCustomAttribute<MessageParameterAttribute>()?.Name
?? typeRootName
?? parameterInfo.Parameter.Name;
?? parameterInfo.Parameter.GetCustomAttribute<MessageParameterAttribute>()?.Name
?? typeRootName
?? parameterInfo.Parameter.Name;

AddSchemaType(writer, parameterInfo.Parameter.ParameterType, parameterName, @namespace: elementAttribute?.Namespace);
}
Expand Down Expand Up @@ -495,13 +495,16 @@ private void AddMessage(XmlDictionaryWriter writer)
}

// output
writer.WriteStartElement("wsdl", "message", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", $"{BindingType}_{operation.Name}_OutputMessage");
writer.WriteStartElement("wsdl", "part", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", "parameters");
writer.WriteAttributeString("element", "tns:" + responseTypeName);
writer.WriteEndElement(); // wsdl:part
writer.WriteEndElement(); // wsdl:message
if (!operation.IsOneWay)
{
writer.WriteStartElement("wsdl", "message", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", $"{BindingType}_{operation.Name}_OutputMessage");
writer.WriteStartElement("wsdl", "part", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", "parameters");
writer.WriteAttributeString("element", "tns:" + responseTypeName);
writer.WriteEndElement(); // wsdl:part
writer.WriteEndElement(); // wsdl:message
}
}
}

Expand All @@ -516,9 +519,12 @@ private void AddPortType(XmlDictionaryWriter writer)
writer.WriteStartElement("wsdl", "input", Namespaces.WSDL_NS);
writer.WriteAttributeString("message", $"tns:{BindingType}_{operation.Name}_InputMessage");
writer.WriteEndElement(); // wsdl:input
writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteAttributeString("message", $"tns:{BindingType}_{operation.Name}_OutputMessage");
writer.WriteEndElement(); // wsdl:output
if (!operation.IsOneWay)
{
writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteAttributeString("message", $"tns:{BindingType}_{operation.Name}_OutputMessage");
writer.WriteEndElement(); // wsdl:output
}
writer.WriteEndElement(); // wsdl:operation
}

Expand Down Expand Up @@ -553,11 +559,14 @@ private void AddBinding(XmlDictionaryWriter writer)
writer.WriteEndElement(); // soap:body
writer.WriteEndElement(); // wsdl:input

writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteStartElement(soap, "body", soapNamespace);
writer.WriteAttributeString("use", "literal");
writer.WriteEndElement(); // soap:body
writer.WriteEndElement(); // wsdl:output
if (!operation.IsOneWay)
{
writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteStartElement(soap, "body", soapNamespace);
writer.WriteAttributeString("use", "literal");
writer.WriteEndElement(); // soap:body
writer.WriteEndElement(); // wsdl:output
}

writer.WriteEndElement(); // wsdl:operation
}
Expand Down
64 changes: 40 additions & 24 deletions src/SoapCore/Meta/MetaWCFBodyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ private void WriteParameters(XmlDictionaryWriter writer, SoapMethodParameterInfo
var parameterName = !string.IsNullOrEmpty(elementAttribute?.ElementName)
? elementAttribute.ElementName
: parameterInfo.Parameter.GetCustomAttribute<MessageParameterAttribute>()?.Name ?? parameterInfo.Parameter.Name;
AddSchemaType(writer, parameterInfo.Parameter.ParameterType, parameterName, objectNamespace: elementAttribute?.Namespace ?? (parameterInfo.Namespace != "http://tempuri.org/" ? parameterInfo.Namespace : null));
var isRequired = !parameterInfo.Parameter.IsOptional;
AddSchemaType(writer, parameterInfo.Parameter.ParameterType, parameterName, objectNamespace: elementAttribute?.Namespace ?? (parameterInfo.Namespace != "http://tempuri.org/" ? parameterInfo.Namespace : null), isRequired: isRequired);
}
}

Expand Down Expand Up @@ -270,7 +271,8 @@ private void AddOperations(XmlDictionaryWriter writer)
}

var returnName = operation.DispatchMethod.ReturnParameter.GetCustomAttribute<MessageParameterAttribute>()?.Name ?? operation.Name + "Result";
AddSchemaType(writer, returnType, returnName, false, GetDataContractNamespace(returnType));
var isRequired = !operation.DispatchMethod.ReturnParameter.IsOptional;
AddSchemaType(writer, returnType, returnName, false, GetDataContractNamespace(returnType), isRequired: isRequired);
}

WriteParameters(writer, operation.OutParameters);
Expand Down Expand Up @@ -796,6 +798,7 @@ private void WriteComplexType(XmlDictionaryWriter writer, Type type)

var attributes = property.GetCustomAttributes(true);
int order = 0;
bool isRequired = false;
foreach (var attr in attributes)
{
if (attr is DataMemberAttribute dataContractAttribute)
Expand All @@ -810,6 +813,8 @@ private void WriteComplexType(XmlDictionaryWriter writer, Type type)
order = dataContractAttribute.Order;
}

isRequired = dataContractAttribute.IsRequired;

break;
}
}
Expand All @@ -818,13 +823,14 @@ private void WriteComplexType(XmlDictionaryWriter writer, Type type)
{
Name = propertyName,
Type = property.PropertyType,
Order = order
Order = order,
IsRequired = isRequired
});
}

foreach (var p in dataMembersToWrite.OrderBy(x => x.Order).ThenBy(p => p.Name, StringComparer.Ordinal))
{
AddSchemaType(writer, p.Type, p.Name, false, GetDataContractNamespace(p.Type));
AddSchemaType(writer, p.Type, p.Name, false, GetDataContractNamespace(p.Type), p.IsRequired);
}
}

Expand Down Expand Up @@ -855,13 +861,16 @@ private void AddMessage(XmlDictionaryWriter writer)
writer.WriteEndElement(); // wsdl:message

// output
writer.WriteStartElement("wsdl", "message", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", $"{BindingType}_{operation.Name}_OutputMessage");
writer.WriteStartElement("wsdl", "part", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", "parameters");
writer.WriteAttributeString("element", "tns:" + operation.Name + "Response");
writer.WriteEndElement(); // wsdl:part
writer.WriteEndElement(); // wsdl:message
if (!operation.IsOneWay)
{
writer.WriteStartElement("wsdl", "message", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", $"{BindingType}_{operation.Name}_OutputMessage");
writer.WriteStartElement("wsdl", "part", Namespaces.WSDL_NS);
writer.WriteAttributeString("name", "parameters");
writer.WriteAttributeString("element", "tns:" + operation.Name + "Response");
writer.WriteEndElement(); // wsdl:part
writer.WriteEndElement(); // wsdl:message
}

AddMessageFaults(writer, operation);
}
Expand Down Expand Up @@ -895,10 +904,14 @@ private void AddPortType(XmlDictionaryWriter writer)
writer.WriteAttributeString("wsam", "Action", Namespaces.WSAM_NS, operation.SoapAction);
writer.WriteAttributeString("message", $"tns:{BindingType}_{operation.Name}_InputMessage");
writer.WriteEndElement(); // wsdl:input
writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteAttributeString("wsam", "Action", Namespaces.WSAM_NS, operation.SoapAction + "Response");
writer.WriteAttributeString("message", $"tns:{BindingType}_{operation.Name}_OutputMessage");
writer.WriteEndElement(); // wsdl:output

if (!operation.IsOneWay)
{
writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteAttributeString("wsam", "Action", Namespaces.WSAM_NS, operation.SoapAction + "Response");
writer.WriteAttributeString("message", $"tns:{BindingType}_{operation.Name}_OutputMessage");
writer.WriteEndElement(); // wsdl:output
}

AddPortTypeFaults(writer, operation);

Expand Down Expand Up @@ -953,11 +966,14 @@ private void AddBinding(XmlDictionaryWriter writer)
writer.WriteEndElement(); // soap:body
writer.WriteEndElement(); // wsdl:input

writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteStartElement("soap", "body", Namespaces.SOAP11_NS);
writer.WriteAttributeString("use", "literal");
writer.WriteEndElement(); // soap:body
writer.WriteEndElement(); // wsdl:output
if (!operation.IsOneWay)
{
writer.WriteStartElement("wsdl", "output", Namespaces.WSDL_NS);
writer.WriteStartElement("soap", "body", Namespaces.SOAP11_NS);
writer.WriteAttributeString("use", "literal");
writer.WriteEndElement(); // soap:body
writer.WriteEndElement(); // wsdl:output
}

AddBindingFaults(writer, operation);

Expand Down Expand Up @@ -1000,7 +1016,7 @@ private void AddService(XmlDictionaryWriter writer)
writer.WriteEndElement(); // wsdl:port
}

private void AddSchemaType(XmlDictionaryWriter writer, Type type, string name, bool isArray = false, string objectNamespace = null)
private void AddSchemaType(XmlDictionaryWriter writer, Type type, string name, bool isArray = false, string objectNamespace = null, bool isRequired = false)
{
var typeInfo = type.GetTypeInfo();
var typeName = GetTypeName(type);
Expand Down Expand Up @@ -1035,7 +1051,7 @@ private void AddSchemaType(XmlDictionaryWriter writer, Type type, string name, b

if (isArray)
{
writer.WriteAttributeString("minOccurs", "0");
writer.WriteAttributeString("minOccurs", isRequired ? "1" : "0");
writer.WriteAttributeString("maxOccurs", "unbounded");
}
}
Expand Down Expand Up @@ -1075,7 +1091,7 @@ private void AddSchemaType(XmlDictionaryWriter writer, Type type, string name, b
}
}

writer.WriteAttributeString("minOccurs", "0");
writer.WriteAttributeString("minOccurs", isRequired ? "1" : "0");
if (isArray)
{
writer.WriteAttributeString("maxOccurs", "unbounded");
Expand All @@ -1091,7 +1107,7 @@ private void AddSchemaType(XmlDictionaryWriter writer, Type type, string name, b
}
else
{
writer.WriteAttributeString("minOccurs", "0");
writer.WriteAttributeString("minOccurs", isRequired ? "1" : "0");
if (isArray)
{
writer.WriteAttributeString("maxOccurs", "unbounded");
Expand Down
1 change: 1 addition & 0 deletions src/SoapCore/ServiceModel/DataMemberDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public class DataMemberDescription
public Type Type { get; set; }
public string Name { get; set; }
public int? Order { get; set; }
public bool IsRequired { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/SoapCore/SoapCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>SOAP protocol middleware for ASP.NET Core</Description>
<VersionPrefix>1.1.0.1-alpha</VersionPrefix>
<VersionPrefix>1.1.0.1-beta</VersionPrefix>
<Authors>Digital Design</Authors>
<TargetFrameworks>netcoreapp3.0;netstandard2.0;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<AssemblyName>SoapCore</AssemblyName>
Expand All @@ -14,7 +14,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.1.0.1-alpha</Version>
<Version>1.1.0.1-beta</Version>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>SoapCore.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down

0 comments on commit a161292

Please sign in to comment.