[Category("NotDotNet")] // hangs on .NET 1.1 #endif public void HandleOutAttributeParameters() { XmlReflectionMember m = new XmlReflectionMember(); m.MemberName = "hooray"; m.MemberType = typeof(string); m.XmlAttributes = new XmlAttributes(); m.XmlAttributes.XmlAttribute = new XmlAttributeAttribute(); XmlReflectionImporter imp = new XmlReflectionImporter(); XmlMembersMapping map = imp.ImportMembersMapping( "elem", "urn:x", new XmlReflectionMember [] { m }, true); XmlSerializer ser = XmlSerializer.FromMappings( new XmlMapping [] { map }) [0]; string xml = "<elem xmlns='urn:x' hooray='doh' />"; object [] arr = ser.Deserialize(new StringReader(xml)) as object []; Assert.IsNotNull(arr, "#1"); Assert.AreEqual(1, arr.Length, "#2"); Assert.AreEqual("doh", arr [0], "#3"); xml = "<elem xmlns='urn:x' hooray='doh'></elem>"; arr = ser.Deserialize(new StringReader(xml)) as object []; Assert.IsNotNull(arr, "#4"); Assert.AreEqual(1, arr.Length, "#5"); Assert.AreEqual("doh", arr [0], "#6"); }
XmlSerializer GetSerializer(MessageBodyDescription desc) { if (bodySerializers.ContainsKey(desc)) { return(bodySerializers [desc]); } int count = desc.Parts.Count + (HasReturnValue(desc) ? 1 : 0); XmlReflectionMember [] members = new XmlReflectionMember [count]; int ind = 0; if (HasReturnValue(desc)) { members [ind++] = CreateReflectionMember(desc.ReturnValue, true); } foreach (MessagePartDescription partDesc in desc.Parts) { members [ind++] = CreateReflectionMember(partDesc, false); } XmlReflectionImporter xmlImporter = new XmlReflectionImporter(); // Register known types into xmlImporter. foreach (var type in OperationKnownTypes) { xmlImporter.IncludeType(type); } XmlMembersMapping [] partsMapping = new XmlMembersMapping [1]; partsMapping [0] = xmlImporter.ImportMembersMapping(desc.WrapperName, desc.WrapperNamespace, members, true); bodySerializers [desc] = XmlSerializer.FromMappings(partsMapping) [0]; return(bodySerializers [desc]); }
XmlReflectionMember [] BuildRequestReflectionMembers(XmlElementAttribute optional_ns) { ParameterInfo [] input = MethodInfo.InParameters; XmlReflectionMember [] in_members = new XmlReflectionMember [input.Length]; for (int i = 0; i < input.Length; i++) { XmlReflectionMember m = new XmlReflectionMember(); m.IsReturnValue = false; m.MemberName = input [i].Name; m.MemberType = input [i].ParameterType; m.XmlAttributes = new XmlAttributes(input[i]); m.SoapAttributes = new SoapAttributes(input[i]); if (m.MemberType.IsByRef) { m.MemberType = m.MemberType.GetElementType(); } if (optional_ns != null) { m.XmlAttributes.XmlElements.Add(optional_ns); } in_members [i] = m; } return(in_members); }
XmlReflectionMember [] BuildHeadersReflectionMembers(HeaderInfo[] headers) { XmlReflectionMember [] mems = new XmlReflectionMember [headers.Length]; for (int n = 0; n < headers.Length; n++) { HeaderInfo header = headers [n]; XmlReflectionMember m = new XmlReflectionMember(); m.IsReturnValue = false; m.MemberName = header.HeaderType.Name; m.MemberType = header.HeaderType; // MS.NET reflects header classes in a weird way. The root element // name is the CLR class name unless it is specified in an XmlRootAttribute. // The usual is to use the xml type name by default, but not in this case. XmlAttributes ats = new XmlAttributes(header.HeaderType); if (ats.XmlRoot != null) { XmlElementAttribute xe = new XmlElementAttribute(); xe.ElementName = ats.XmlRoot.ElementName; xe.Namespace = ats.XmlRoot.Namespace; m.XmlAttributes = new XmlAttributes(); m.XmlAttributes.XmlElements.Add(xe); } mems [n] = m; } return(mems); }
internal XmlMembersMapping ImportFaultElement(FaultDescription fault, out XmlQualifiedName elementName) { // the number of reflection members is always 1 because there is only one fault detail type XmlReflectionMember[] members = new XmlReflectionMember[1]; XmlName faultElementName = fault.ElementName; string faultNamespace = fault.Namespace; if (faultElementName == null) { XmlTypeMapping mapping = _parent._importer.ImportTypeMapping(fault.DetailType); faultElementName = new XmlName(mapping.ElementName, false /*isEncoded*/); faultNamespace = mapping.Namespace; if (faultElementName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.SFxFaultTypeAnonymous, this.Operation.Name, fault.DetailType.FullName))); } } elementName = new XmlQualifiedName(faultElementName.DecodedName, faultNamespace); members[0] = XmlSerializerHelper.GetXmlReflectionMember(null /*memberName*/, faultElementName, faultNamespace, fault.DetailType, null /*additionalAttributesProvider*/, false /*isMultiple*/, false /*isWrapped*/); string mappingKey = "fault:" + faultElementName.DecodedName + ":" + faultNamespace; return(ImportMembersMapping(faultElementName.EncodedName, faultNamespace, members, false /*hasWrapperElement*/, this.IsRpc, mappingKey)); }
private MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, XmlSchemaForm form, RecursionLimiter limiter) { SoapAttributes a = xmlReflectionMember.SoapAttributes; if (a.SoapIgnore) { return(null); } MemberMapping member = new MemberMapping(); member.IsSoap = true; member.Name = xmlReflectionMember.MemberName; bool checkSpecified = XmlReflectionImporter.FindSpecifiedMember(xmlReflectionMember.MemberName, xmlReflectionMembers) != null; FieldModel model = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, _typeScope.GetTypeDesc(xmlReflectionMember.MemberType), checkSpecified, false); member.CheckShouldPersist = model.CheckShouldPersist; member.CheckSpecified = model.CheckSpecified; member.ReadOnly = model.ReadOnly; // || !model.FieldTypeDesc.HasDefaultConstructor; ImportAccessorMapping(member, model, a, ns, form, limiter); if (xmlReflectionMember.OverrideIsNullable) { member.Elements[0].IsNullable = false; } return(member); }
private XmlReflectionMember CreateReflectionMember(MessagePartDescription partDesc, bool isReturnValue) { XmlReflectionMember m = new XmlReflectionMember(); m.IsReturnValue = isReturnValue; m.MemberName = partDesc.Name; m.MemberType = partDesc.Type; return(m); }
private XmlReflectionMember CreateReflectionMember(MessagePartDescription partDesc, bool isReturnValue) { XmlReflectionMember m = new XmlReflectionMember(); m.IsReturnValue = isReturnValue; m.MemberName = partDesc.Name; m.MemberType = partDesc.Type; m.XmlAttributes = partDesc.MemberInfo == null ? new XmlAttributes() : new XmlAttributes(partDesc.MemberInfo); return(m); }
private XmlMembersMapping LoadBodyMapping(MessageDescription message, string mappingKey, out MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts) { MessagePartDescription description; string name; string wrapperNamespace; MessagePartDescriptionCollection parts; if ((this.IsEncoded && message.IsTypedMessage) && (message.Body.WrapperName == null)) { MessagePartDescription wrapperPart = this.GetWrapperPart(message); description = null; rpcEncodedTypedMessageBodyParts = parts = this.GetWrappedParts(wrapperPart); name = wrapperPart.Name; wrapperNamespace = wrapperPart.Namespace; } else { rpcEncodedTypedMessageBodyParts = null; description = OperationFormatter.IsValidReturnValue(message.Body.ReturnValue) ? message.Body.ReturnValue : null; parts = message.Body.Parts; name = message.Body.WrapperName; wrapperNamespace = message.Body.WrapperNamespace; } bool isWrapped = name != null; bool flag2 = description != null; int num = parts.Count + (flag2 ? 1 : 0); if ((num == 0) && !isWrapped) { return(null); } XmlReflectionMember[] members = new XmlReflectionMember[num]; int num2 = 0; if (flag2) { members[num2++] = XmlSerializerHelper.GetXmlReflectionMember(description, this.IsRpc, this.IsEncoded, isWrapped); } for (int i = 0; i < parts.Count; i++) { members[num2++] = XmlSerializerHelper.GetXmlReflectionMember(parts[i], this.IsRpc, this.IsEncoded, isWrapped); } if (!isWrapped) { wrapperNamespace = this.ContractNamespace; } return(this.ImportMembersMapping(name, wrapperNamespace, members, isWrapped, this.IsRpc, mappingKey)); }
XmlReflectionMember [] BuildResponseReflectionMembers(XmlElementAttribute optional_ns) { ParameterInfo [] output = MethodInfo.OutParameters; bool has_return_value = !(OneWay || MethodInfo.ReturnType == typeof(void)); XmlReflectionMember [] out_members = new XmlReflectionMember [(has_return_value ? 1 : 0) + output.Length]; XmlReflectionMember m; int idx = 0; if (has_return_value) { m = new XmlReflectionMember(); m.IsReturnValue = true; m.MemberName = Name + "Result"; m.MemberType = MethodInfo.ReturnType; m.XmlAttributes = new XmlAttributes(MethodInfo.ReturnTypeCustomAttributeProvider); m.SoapAttributes = new SoapAttributes(MethodInfo.ReturnTypeCustomAttributeProvider); if (optional_ns != null) { m.XmlAttributes.XmlElements.Add(optional_ns); } idx++; out_members [0] = m; } for (int i = 0; i < output.Length; i++) { m = new XmlReflectionMember(); m.IsReturnValue = false; m.MemberName = output [i].Name; m.MemberType = output [i].ParameterType; m.XmlAttributes = new XmlAttributes(output[i]); m.SoapAttributes = new SoapAttributes(output[i]); if (m.MemberType.IsByRef) { m.MemberType = m.MemberType.GetElementType(); } if (optional_ns != null) { m.XmlAttributes.XmlElements.Add(optional_ns); } out_members [i + idx] = m; } return(out_members); }
static EchoRpcEncWithHeadersService() { var member = new XmlReflectionMember { MemberName = "StringHeader", MemberType = typeof(StringHeader), SoapAttributes = new SoapAttributes { SoapElement = new SoapElementAttribute("StringHeader") } }; var members = new XmlReflectionMember[] { member }; var mappings = new SoapReflectionImporter().ImportMembersMapping("EchoServiceSoap", "http://tempuri.org/", members, false, false); var serializers = XmlSerializer.FromMappings(new XmlMembersMapping[] { mappings }, typeof(EchoRpcEncWithHeadersService)); s_stringHeaderSerializer = serializers[0]; }
private MembersMapping ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, string ns, bool hasWrapperElement, bool writeAccessors, bool validateWrapperElement, RecursionLimiter limiter) { MembersMapping members = new MembersMapping(); members.TypeDesc = _typeScope.GetTypeDesc(typeof(object[])); MemberMapping[] mappings = new MemberMapping[xmlReflectionMembers.Length]; for (int i = 0; i < mappings.Length; i++) { try { XmlReflectionMember member = xmlReflectionMembers[i]; MemberMapping mapping = ImportMemberMapping(member, ns, xmlReflectionMembers, hasWrapperElement ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified, limiter); if (member.IsReturnValue && writeAccessors) { // no special treatment for return values with doc/enc if (i > 0) { throw new InvalidOperationException(SR.XmlInvalidReturnPosition); } mapping.IsReturnValue = true; } mappings[i] = mapping; } catch (Exception e) { if (e is OutOfMemoryException) { throw; } throw ReflectionException(xmlReflectionMembers[i].MemberName, e); } } members.Members = mappings; members.HasWrapperElement = hasWrapperElement; if (hasWrapperElement) { members.ValidateRpcWrapperElement = validateWrapperElement; } members.WriteAccessors = writeAccessors; members.IsSoap = true; if (hasWrapperElement && !writeAccessors) { members.Namespace = ns; } return(members); }
private XmlMembersMapping LoadHeadersMapping(MessageDescription message, string mappingKey) { int count = message.Headers.Count; if (count == 0) { return(null); } if (this.IsEncoded) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxHeadersAreNotSupportedInEncoded", new object[] { message.MessageName }))); } int num2 = 0; int num3 = 0; XmlReflectionMember[] sourceArray = new XmlReflectionMember[count]; for (int i = 0; i < count; i++) { MessageHeaderDescription part = message.Headers[i]; if (!part.IsUnknownHeaderCollection) { sourceArray[num3++] = XmlSerializerHelper.GetXmlReflectionMember(part, false, this.IsEncoded, false); } else { num2++; } } if (num2 == count) { return(null); } if (num2 > 0) { XmlReflectionMember[] destinationArray = new XmlReflectionMember[count - num2]; Array.Copy(sourceArray, destinationArray, destinationArray.Length); sourceArray = destinationArray; } return(this.ImportMembersMapping(this.ContractName, this.ContractNamespace, sourceArray, false, false, mappingKey)); }
internal XmlMembersMapping ImportFaultElement(FaultDescription fault, out XmlQualifiedName elementName) { XmlReflectionMember[] members = new XmlReflectionMember[1]; System.ServiceModel.Description.XmlName name = fault.ElementName; string ns = fault.Namespace; if (name == null) { XmlTypeMapping mapping = this.parent.importer.ImportTypeMapping(fault.DetailType, this.IsEncoded); name = new System.ServiceModel.Description.XmlName(mapping.ElementName, this.IsEncoded); ns = mapping.Namespace; if (name == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxFaultTypeAnonymous", new object[] { this.Operation.Name, fault.DetailType.FullName }))); } } elementName = new XmlQualifiedName(name.DecodedName, ns); members[0] = XmlSerializerHelper.GetXmlReflectionMember(null, name, ns, fault.DetailType, null, false, this.IsEncoded, false); string mappingKey = "fault:" + name.DecodedName + ":" + ns; return(this.ImportMembersMapping(name.EncodedName, ns, members, false, this.IsRpc, mappingKey)); }
public void ExportXmlSerializable_NestedClassMapping() { XmlSchemas schemas = new XmlSchemas(); XmlReflectionMember xmlReflectionMember = new XmlReflectionMember(); XmlSchemaExporter xmlSchemaExporter = new XmlSchemaExporter(schemas); XmlReflectionImporter xmlReflectionImporter = new XmlReflectionImporter(); //Export mapping for DataSet1 class. xmlReflectionMember.MemberType = typeof(DataSet1); XmlMembersMapping xmlMembersMapping = xmlReflectionImporter.ImportMembersMapping("DataSet1Response", "ResponseNamespace", new XmlReflectionMember [] { xmlReflectionMember }, true); xmlSchemaExporter.ExportMembersMapping(xmlMembersMapping); //Export mapping for nested of DataSet1 class. xmlReflectionMember.MemberType = typeof(DataSet1.DataTable1DataTable); xmlMembersMapping = xmlReflectionImporter.ImportMembersMapping("DataTable1DataTableResponse", "ResponseNamespace", new XmlReflectionMember [] { xmlReflectionMember }, true); xmlSchemaExporter.ExportMembersMapping(xmlMembersMapping); }
private XmlMembersMapping LoadBodyMapping(MessageDescription message, string mappingKey, out MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts) { MessagePartDescription returnPart; string wrapperName, wrapperNs; MessagePartDescriptionCollection bodyParts; rpcEncodedTypedMessageBodyParts = null; returnPart = OperationFormatter.IsValidReturnValue(message.Body.ReturnValue) ? message.Body.ReturnValue : null; bodyParts = message.Body.Parts; wrapperName = message.Body.WrapperName; wrapperNs = message.Body.WrapperNamespace; bool isWrapped = (wrapperName != null); bool hasReturnValue = returnPart != null; int paramCount = bodyParts.Count + (hasReturnValue ? 1 : 0); if (paramCount == 0 && !isWrapped) // no need to create serializer { return(null); } XmlReflectionMember[] members = new XmlReflectionMember[paramCount]; int paramIndex = 0; if (hasReturnValue) { members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(returnPart, IsRpc, isWrapped); } for (int i = 0; i < bodyParts.Count; i++) { members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(bodyParts[i], IsRpc, isWrapped); } if (!isWrapped) { wrapperNs = ContractNamespace; } return(ImportMembersMapping(wrapperName, wrapperNs, members, isWrapped, IsRpc, mappingKey)); }
private XmlMembersMapping LoadHeadersMapping(MessageDescription message, string mappingKey) { int headerCount = message.Headers.Count; if (headerCount == 0) { return(null); } int unknownHeaderCount = 0, headerIndex = 0; XmlReflectionMember[] members = new XmlReflectionMember[headerCount]; for (int i = 0; i < headerCount; i++) { MessageHeaderDescription header = message.Headers[i]; if (!header.IsUnknownHeaderCollection) { members[headerIndex++] = XmlSerializerHelper.GetXmlReflectionMember(header, false /*isRpc*/, false /*isWrapped*/); } else { unknownHeaderCount++; } } if (unknownHeaderCount == headerCount) { return(null); } if (unknownHeaderCount > 0) { XmlReflectionMember[] newMembers = new XmlReflectionMember[headerCount - unknownHeaderCount]; Array.Copy(members, newMembers, newMembers.Length); members = newMembers; } return(ImportMembersMapping(ContractName, ContractNamespace, members, false /*isWrapped*/, false /*isRpc*/, mappingKey)); }
static internal XmlReflectionMember GetXmlReflectionMember(XmlName memberName, XmlName elementName, string ns, Type type, MemberInfo additionalAttributesProvider, bool isMultiple, bool isWrapped) { XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = (memberName ?? elementName).DecodedName; member.MemberType = type; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } if (isMultiple) { member.MemberType = member.MemberType.MakeArrayType(); } if (additionalAttributesProvider != null) { //member.XmlAttributes = XmlAttributesHelper.CreateXmlAttributes(additionalAttributesProvider); member.XmlAttributes = new XmlAttributes(additionalAttributesProvider.GetCustomAttributes()); } if (member.XmlAttributes == null) { member.XmlAttributes = new XmlAttributes(); } else { Type invalidAttributeType = null; if (member.XmlAttributes.XmlAttribute != null) { invalidAttributeType = typeof(XmlAttributeAttribute); } else if (member.XmlAttributes.XmlAnyAttribute != null && !isWrapped) { invalidAttributeType = typeof(XmlAnyAttributeAttribute); } else if (member.XmlAttributes.XmlChoiceIdentifier != null) { invalidAttributeType = typeof(XmlChoiceIdentifierAttribute); } else if (member.XmlAttributes.XmlIgnore) { invalidAttributeType = typeof(XmlIgnoreAttribute); } else if (member.XmlAttributes.Xmlns) { invalidAttributeType = typeof(XmlNamespaceDeclarationsAttribute); } else if (member.XmlAttributes.XmlText != null) { invalidAttributeType = typeof(XmlTextAttribute); } else if (member.XmlAttributes.XmlEnum != null) { invalidAttributeType = typeof(XmlEnumAttribute); } if (invalidAttributeType != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(isWrapped ? SRServiceModel.SFxInvalidXmlAttributeInWrapped : SRServiceModel.SFxInvalidXmlAttributeInBare, invalidAttributeType, elementName.DecodedName))); } if (member.XmlAttributes.XmlArray != null && isMultiple) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.SFxXmlArrayNotAllowedForMultiple, elementName.DecodedName, ns))); } } bool isArray = member.MemberType.IsArray; if ((isArray && !isMultiple && member.MemberType != typeof(byte[])) || (!isArray && typeof(IEnumerable).IsAssignableFrom(member.MemberType) && member.MemberType != typeof(string) && !typeof(XmlNode).IsAssignableFrom(member.MemberType) && !typeof(IXmlSerializable).IsAssignableFrom(member.MemberType))) { if (member.XmlAttributes.XmlArray != null) { if (member.XmlAttributes.XmlArray.ElementName == String.Empty) { member.XmlAttributes.XmlArray.ElementName = elementName.DecodedName; } if (member.XmlAttributes.XmlArray.Namespace == null) { member.XmlAttributes.XmlArray.Namespace = ns; } } else if (HasNoXmlParameterAttributes(member.XmlAttributes)) { member.XmlAttributes.XmlArray = new XmlArrayAttribute(); member.XmlAttributes.XmlArray.ElementName = elementName.DecodedName; member.XmlAttributes.XmlArray.Namespace = ns; } } else { if (member.XmlAttributes.XmlElements == null || member.XmlAttributes.XmlElements.Count == 0) { if (HasNoXmlParameterAttributes(member.XmlAttributes)) { XmlElementAttribute elementAttribute = new XmlElementAttribute(); elementAttribute.ElementName = elementName.DecodedName; elementAttribute.Namespace = ns; member.XmlAttributes.XmlElements.Add(elementAttribute); } } else { foreach (XmlElementAttribute elementAttribute in member.XmlAttributes.XmlElements) { if (elementAttribute.ElementName == String.Empty) { elementAttribute.ElementName = elementName.DecodedName; } if (elementAttribute.Namespace == null) { elementAttribute.Namespace = ns; } } } } return(member); }
public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access) { }
public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool rpc);
public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool rpc, bool openModel, XmlMappingAccess access);
internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs) { try { SoapReflectedMethod soapMethod = new SoapReflectedMethod(); MethodAttribute methodAttribute = new MethodAttribute(); object serviceAttr = GetSoapServiceAttribute(methodInfo.DeclaringType); bool serviceDefaultIsEncoded = ServiceDefaultIsEncoded(serviceAttr); object methodAttr = GetSoapMethodAttribute(methodInfo); if (methodAttr == null) { if (client) { return(null); // method attribute required on the client } if (serviceAttr is SoapRpcServiceAttribute) { methodAttr = new SoapRpcMethodAttribute(); } else { methodAttr = new SoapDocumentMethodAttribute(); } } if (methodAttr is SoapRpcMethodAttribute) { SoapRpcMethodAttribute attr = (SoapRpcMethodAttribute)methodAttr; soapMethod.rpc = true; soapMethod.use = SoapBindingUse.Encoded; soapMethod.oneWay = attr.OneWay; methodAttribute.action = attr.Action; methodAttribute.binding = attr.Binding; methodAttribute.requestName = attr.RequestElementName; methodAttribute.requestNs = attr.RequestNamespace; methodAttribute.responseName = attr.ResponseElementName; methodAttribute.responseNs = attr.ResponseNamespace; } else { SoapDocumentMethodAttribute attr = (SoapDocumentMethodAttribute)methodAttr; soapMethod.rpc = false; soapMethod.use = attr.Use; soapMethod.paramStyle = attr.ParameterStyle; soapMethod.oneWay = attr.OneWay; methodAttribute.action = attr.Action; methodAttribute.binding = attr.Binding; methodAttribute.requestName = attr.RequestElementName; methodAttribute.requestNs = attr.RequestNamespace; methodAttribute.responseName = attr.ResponseElementName; methodAttribute.responseNs = attr.ResponseNamespace; if (soapMethod.use == SoapBindingUse.Default) { if (serviceAttr is SoapDocumentServiceAttribute) { soapMethod.use = ((SoapDocumentServiceAttribute)serviceAttr).Use; } if (soapMethod.use == SoapBindingUse.Default) { soapMethod.use = SoapBindingUse.Literal; } } if (soapMethod.paramStyle == SoapParameterStyle.Default) { if (serviceAttr is SoapDocumentServiceAttribute) { soapMethod.paramStyle = ((SoapDocumentServiceAttribute)serviceAttr).ParameterStyle; } if (soapMethod.paramStyle == SoapParameterStyle.Default) { soapMethod.paramStyle = SoapParameterStyle.Wrapped; } } } if (methodAttribute.binding.Length > 0) { if (client) { throw new InvalidOperationException(Res.GetString(Res.WebInvalidBindingPlacement, methodAttr.GetType().Name)); } soapMethod.binding = WebServiceBindingReflector.GetAttribute(methodInfo, methodAttribute.binding); } WebMethodAttribute webMethodAttribute = WebMethodReflector.GetAttribute(methodInfo); soapMethod.name = webMethodAttribute.MessageName; if (soapMethod.name.Length == 0) { soapMethod.name = methodInfo.Name; } string requestElementName; if (soapMethod.rpc) { requestElementName = methodInfo.Name; } else { requestElementName = methodAttribute.requestName.Length == 0 ? soapMethod.name : methodAttribute.requestName; } string requestNamespace = methodAttribute.requestNs; if (requestNamespace == null) { if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0) { requestNamespace = soapMethod.binding.Namespace; } else { requestNamespace = defaultNs; } } string responseElementName = methodAttribute.responseName.Length == 0 ? soapMethod.name + "Response": methodAttribute.responseName; string responseNamespace = methodAttribute.responseNs; if (responseNamespace == null) { if (soapMethod.binding != null && soapMethod.binding.Namespace != null && soapMethod.binding.Namespace.Length != 0) { responseNamespace = soapMethod.binding.Namespace; } else { responseNamespace = defaultNs; } } SoapParameterInfo[] inParameters = ReflectParameters(methodInfo.InParameters, requestNamespace); SoapParameterInfo[] outParameters = ReflectParameters(methodInfo.OutParameters, responseNamespace); soapMethod.action = methodAttribute.action; if (soapMethod.action == null) { soapMethod.action = GetDefaultAction(defaultNs, methodInfo); } soapMethod.methodInfo = methodInfo; if (soapMethod.oneWay) { if (outParameters.Length > 0) { throw new ArgumentException(Res.GetString(Res.WebOneWayOutParameters), "methodInfo"); } if (methodInfo.ReturnType != typeof(void)) { throw new ArgumentException(Res.GetString(Res.WebOneWayReturnValue), "methodInfo"); } } XmlReflectionMember[] members = new XmlReflectionMember[inParameters.Length]; for (int i = 0; i < members.Length; i++) { SoapParameterInfo soapParamInfo = inParameters[i]; XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = soapParamInfo.parameterInfo.Name; member.MemberType = soapParamInfo.parameterInfo.ParameterType; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } member.XmlAttributes = soapParamInfo.xmlAttributes; member.SoapAttributes = soapParamInfo.soapAttributes; members[i] = member; } soapMethod.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, requestElementName, requestNamespace, methodAttribute.requestNs == null, members, true); if (GetSoapServiceRoutingStyle(serviceAttr) == SoapServiceRoutingStyle.RequestElement && soapMethod.paramStyle == SoapParameterStyle.Bare && soapMethod.requestMappings.Count != 1) { throw new ArgumentException(Res.GetString(Res.WhenUsingAMessageStyleOfParametersAsDocument0), "methodInfo"); } string elementName = ""; string elementNamespace = ""; if (soapMethod.paramStyle == SoapParameterStyle.Bare) { if (soapMethod.requestMappings.Count == 1) { elementName = soapMethod.requestMappings[0].ElementName; elementNamespace = soapMethod.requestMappings[0].Namespace; } // else: can't route on request element -- we match on an empty qname, // normal rules apply for duplicates } else { elementName = soapMethod.requestMappings.ElementName; elementNamespace = soapMethod.requestMappings.Namespace; } soapMethod.requestElementName = new XmlQualifiedName(elementName, elementNamespace); if (!soapMethod.oneWay) { int numOutParams = outParameters.Length; int count = 0; CodeIdentifiers identifiers = null; if (methodInfo.ReturnType != typeof(void)) { numOutParams++; count = 1; identifiers = new CodeIdentifiers(); } members = new XmlReflectionMember[numOutParams]; for (int i = 0; i < outParameters.Length; i++) { SoapParameterInfo soapParamInfo = outParameters[i]; XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = soapParamInfo.parameterInfo.Name; member.MemberType = soapParamInfo.parameterInfo.ParameterType; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } member.XmlAttributes = soapParamInfo.xmlAttributes; member.SoapAttributes = soapParamInfo.soapAttributes; members[count++] = member; if (identifiers != null) { identifiers.Add(member.MemberName, null); } } if (methodInfo.ReturnType != typeof(void)) { XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = identifiers.MakeUnique(soapMethod.name + "Result"); member.MemberType = methodInfo.ReturnType; member.IsReturnValue = true; member.XmlAttributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider); member.XmlAttributes.XmlRoot = null; // Ignore XmlRoot attribute used by get/post member.SoapAttributes = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider); members[0] = member; } soapMethod.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, soapMethod.rpc, soapMethod.use, soapMethod.paramStyle, responseElementName, responseNamespace, methodAttribute.responseNs == null, members, false); } SoapExtensionAttribute[] extensionAttributes = (SoapExtensionAttribute[])methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute)); soapMethod.extensions = new SoapReflectedExtension[extensionAttributes.Length]; for (int i = 0; i < extensionAttributes.Length; i++) { soapMethod.extensions[i] = new SoapReflectedExtension(extensionAttributes[i].ExtensionType, extensionAttributes[i]); } Array.Sort(soapMethod.extensions); SoapHeaderAttribute[] headerAttributes = (SoapHeaderAttribute[])methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute)); Array.Sort(headerAttributes, new SoapHeaderAttributeComparer()); Hashtable headerTypes = new Hashtable(); soapMethod.headers = new SoapReflectedHeader[headerAttributes.Length]; int front = 0; int back = soapMethod.headers.Length; ArrayList inHeaders = new ArrayList(); ArrayList outHeaders = new ArrayList(); for (int i = 0; i < soapMethod.headers.Length; i++) { SoapHeaderAttribute headerAttribute = headerAttributes[i]; SoapReflectedHeader soapHeader = new SoapReflectedHeader(); Type declaringType = methodInfo.DeclaringType; if ((soapHeader.memberInfo = declaringType.GetField(headerAttribute.MemberName)) != null) { soapHeader.headerType = ((FieldInfo)soapHeader.memberInfo).FieldType; } else if ((soapHeader.memberInfo = declaringType.GetProperty(headerAttribute.MemberName)) != null) { soapHeader.headerType = ((PropertyInfo)soapHeader.memberInfo).PropertyType; } else { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderMissing); } if (soapHeader.headerType.IsArray) { soapHeader.headerType = soapHeader.headerType.GetElementType(); soapHeader.repeats = true; if (soapHeader.headerType != typeof(SoapUnknownHeader) && soapHeader.headerType != typeof(SoapHeader)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType); } } if (MemberHelper.IsStatic(soapHeader.memberInfo)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderStatic); } if (!MemberHelper.CanRead(soapHeader.memberInfo)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderRead); } if (!MemberHelper.CanWrite(soapHeader.memberInfo)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderWrite); } if (!typeof(SoapHeader).IsAssignableFrom(soapHeader.headerType)) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderType); } SoapHeaderDirection direction = headerAttribute.Direction; if (soapMethod.oneWay && (direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebHeaderOneWayOut); } if (headerTypes.Contains(soapHeader.headerType)) { SoapHeaderDirection prevDirection = (SoapHeaderDirection)headerTypes[soapHeader.headerType]; if ((prevDirection & direction) != 0) { throw HeaderException(headerAttribute.MemberName, methodInfo.DeclaringType, Res.WebMultiplyDeclaredHeaderTypes); } headerTypes[soapHeader.headerType] = direction | prevDirection; } else { headerTypes[soapHeader.headerType] = direction; } if (soapHeader.headerType != typeof(SoapHeader) && soapHeader.headerType != typeof(SoapUnknownHeader)) { XmlReflectionMember member = new XmlReflectionMember(); member.MemberName = soapHeader.headerType.Name; member.MemberType = soapHeader.headerType; member.OverrideIsNullable = true; if ((direction & SoapHeaderDirection.In) != 0) { inHeaders.Add(member); } if ((direction & (SoapHeaderDirection.Out | SoapHeaderDirection.Fault)) != 0) { outHeaders.Add(member); } soapHeader.custom = true; } soapHeader.direction = direction; // Put generic header mappings at the end of the list so they are found last during header processing if (!soapHeader.custom) { soapMethod.headers[--back] = soapHeader; } else { soapMethod.headers[front++] = soapHeader; } } soapMethod.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, "InHeaders", defaultNs, true, (XmlReflectionMember[])inHeaders.ToArray(typeof(XmlReflectionMember)), false); if (!soapMethod.oneWay) { soapMethod.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, soapMethod.use, SoapParameterStyle.Bare, "OutHeaders", defaultNs, true, (XmlReflectionMember[])outHeaders.ToArray(typeof(XmlReflectionMember)), false); } return(soapMethod); } catch (Exception e) { throw new InvalidOperationException(Res.GetString(Res.WebReflectionErrorMethod, methodInfo.DeclaringType.Name, methodInfo.Name), e); } }
internal static XmlReflectionMember GetXmlReflectionMember(System.ServiceModel.Description.XmlName memberName, System.ServiceModel.Description.XmlName elementName, string ns, Type type, ICustomAttributeProvider additionalAttributesProvider, bool isMultiple, bool isEncoded, bool isWrapped) { if (isEncoded && isMultiple) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxMultiplePartsNotAllowedInEncoded", new object[] { elementName.DecodedName, ns }))); } XmlReflectionMember member = new XmlReflectionMember { MemberName = (memberName ?? elementName).DecodedName, MemberType = type }; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } if (isMultiple) { member.MemberType = member.MemberType.MakeArrayType(); } if (additionalAttributesProvider != null) { if (isEncoded) { member.SoapAttributes = new SoapAttributes(additionalAttributesProvider); } else { member.XmlAttributes = new XmlAttributes(additionalAttributesProvider); } } if (isEncoded) { if (member.SoapAttributes == null) { member.SoapAttributes = new SoapAttributes(); } else { Type type2 = null; if (member.SoapAttributes.SoapAttribute != null) { type2 = typeof(SoapAttributeAttribute); } else if (member.SoapAttributes.SoapIgnore) { type2 = typeof(SoapIgnoreAttribute); } else if (member.SoapAttributes.SoapType != null) { type2 = typeof(SoapTypeAttribute); } if (type2 != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidSoapAttribute", new object[] { type2, elementName.DecodedName }))); } } if (member.SoapAttributes.SoapElement == null) { member.SoapAttributes.SoapElement = new SoapElementAttribute(elementName.DecodedName); } return(member); } if (member.XmlAttributes == null) { member.XmlAttributes = new XmlAttributes(); } else { Type type3 = null; if (member.XmlAttributes.XmlAttribute != null) { type3 = typeof(XmlAttributeAttribute); } else if ((member.XmlAttributes.XmlAnyAttribute != null) && !isWrapped) { type3 = typeof(XmlAnyAttributeAttribute); } else if (member.XmlAttributes.XmlChoiceIdentifier != null) { type3 = typeof(XmlChoiceIdentifierAttribute); } else if (member.XmlAttributes.XmlIgnore) { type3 = typeof(XmlIgnoreAttribute); } else if (member.XmlAttributes.Xmlns) { type3 = typeof(XmlNamespaceDeclarationsAttribute); } else if (member.XmlAttributes.XmlText != null) { type3 = typeof(XmlTextAttribute); } else if (member.XmlAttributes.XmlEnum != null) { type3 = typeof(XmlEnumAttribute); } if (type3 != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString(isWrapped ? "SFxInvalidXmlAttributeInWrapped" : "SFxInvalidXmlAttributeInBare", new object[] { type3, elementName.DecodedName }))); } if ((member.XmlAttributes.XmlArray != null) && isMultiple) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxXmlArrayNotAllowedForMultiple", new object[] { elementName.DecodedName, ns }))); } } bool isArray = member.MemberType.IsArray; if (((isArray && !isMultiple) && (member.MemberType != typeof(byte[]))) || (((!isArray && typeof(IEnumerable).IsAssignableFrom(member.MemberType)) && ((member.MemberType != typeof(string)) && !typeof(System.Xml.XmlNode).IsAssignableFrom(member.MemberType))) && !typeof(IXmlSerializable).IsAssignableFrom(member.MemberType))) { if (member.XmlAttributes.XmlArray != null) { if (member.XmlAttributes.XmlArray.ElementName == string.Empty) { member.XmlAttributes.XmlArray.ElementName = elementName.DecodedName; } if (member.XmlAttributes.XmlArray.Namespace == null) { member.XmlAttributes.XmlArray.Namespace = ns; } return(member); } if (HasNoXmlParameterAttributes(member.XmlAttributes)) { member.XmlAttributes.XmlArray = new XmlArrayAttribute(); member.XmlAttributes.XmlArray.ElementName = elementName.DecodedName; member.XmlAttributes.XmlArray.Namespace = ns; } return(member); } if ((member.XmlAttributes.XmlElements == null) || (member.XmlAttributes.XmlElements.Count == 0)) { if (HasNoXmlParameterAttributes(member.XmlAttributes)) { XmlElementAttribute attribute = new XmlElementAttribute { ElementName = elementName.DecodedName, Namespace = ns }; member.XmlAttributes.XmlElements.Add(attribute); } return(member); } foreach (XmlElementAttribute attribute2 in member.XmlAttributes.XmlElements) { if (attribute2.ElementName == string.Empty) { attribute2.ElementName = elementName.DecodedName; } if (attribute2.Namespace == null) { attribute2.Namespace = ns; } } return(member); }
protected override bool ReflectMethod() { LogicalTypeInfo ti = TypeStubManager.GetLogicalTypeInfo(ServiceType); HttpOperationBinding sob = new HttpOperationBinding(); sob.Location = "/" + MethodStubInfo.Name; OperationBinding.Extensions.Add(sob); if (!Method.IsVoid) { MimeXmlBinding mxb = new MimeXmlBinding(); mxb.Part = "Body"; OperationBinding.Output.Extensions.Add(mxb); MessagePart part = new MessagePart(); part.Name = "Body"; XmlTypeMapping map = ReflectionImporter.ImportTypeMapping(Method.ReturnType, ti.GetWebServiceLiteralNamespace(ServiceDescription.TargetNamespace)); XmlQualifiedName qname = new XmlQualifiedName(map.ElementName, map.Namespace); part.Element = qname; OutputMessage.Parts.Add(part); SchemaExporter.ExportTypeMapping(map); } XmlReflectionMember[] mems = new XmlReflectionMember [Method.Parameters.Length]; for (int n = 0; n < Method.Parameters.Length; n++) { ParameterInfo param = Method.Parameters [n]; XmlReflectionMember mem = new XmlReflectionMember(); mem.MemberName = param.Name; Type ptype = param.ParameterType; if (ptype.IsByRef) { ptype = ptype.GetElementType(); } mem.MemberType = ptype; mems [n] = mem; } XmlMembersMapping memap = ReflectionImporter.ImportMembersMapping("", ti.WebServiceAbstractNamespace, mems, false); bool allPrimitives = true; for (int n = 0; n < memap.Count; n++) { XmlMemberMapping mem = memap[n]; MessagePart part = new MessagePart(); XmlQualifiedName pqname; if (mem.TypeNamespace == "") { pqname = new XmlQualifiedName(mem.TypeName, XmlSchema.Namespace); } else { pqname = new XmlQualifiedName(mem.TypeName, mem.TypeNamespace); allPrimitives = false; } part.Type = pqname; part.Name = mem.ElementName; InputMessage.Parts.Add(part); } if (!allPrimitives) { SoapSchemaExporter.ExportMembersMapping(memap); } return(true); }
public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members) { }
private object[] GetRequestArguments(Message requestMessage, System.Xml.XmlDictionaryReader xmlReader, OperationDescription operation, HttpContext httpContext) { var arguments = new object[operation.AllParameters.Length]; IEnumerable <Type> serviceKnownTypes = operation .GetServiceKnownTypesHierarchy() .Select(x => x.Type); // if any ordering issues, possible to rewrite like: /*while (!xmlReader.EOF) * { * var parameterInfo = operation.InParameters.FirstOrDefault(p => p.Name == xmlReader.LocalName && p.Namespace == xmlReader.NamespaceURI); * if (parameterInfo == null) * { * xmlReader.Skip(); * continue; * } * var parameterName = parameterInfo.Name; * var parameterNs = parameterInfo.Namespace; * ... * }*/ // Find the element for the operation's data if (!operation.IsMessageContractRequest) { xmlReader.ReadStartElement(operation.Name, operation.Contract.Namespace); foreach (var parameterInfo in operation.InParameters) { var parameterType = parameterInfo.Parameter.ParameterType; if (parameterType == typeof(HttpContext)) { arguments[parameterInfo.Index] = httpContext; } else { var argumentValue = _serializerHelper.DeserializeInputParameter( xmlReader, parameterType, parameterInfo.Name, operation.Contract.Namespace, parameterInfo.Parameter.Member, serviceKnownTypes); //fix https://github.com/DigDes/SoapCore/issues/379 (hack, need research) if (argumentValue == null) { argumentValue = _serializerHelper.DeserializeInputParameter( xmlReader, parameterType, parameterInfo.Name, parameterInfo.Namespace, parameterInfo.Parameter.Member, serviceKnownTypes); } arguments[parameterInfo.Index] = argumentValue; } } } else { // MessageContracts are constrained to having one "InParameter". We can do special logic on // for this Debug.Assert(operation.InParameters.Length == 1, "MessageContracts are constrained to having one 'InParameter'"); var parameterInfo = operation.InParameters[0]; var parameterType = parameterInfo.Parameter.ParameterType; var messageContractAttribute = parameterType.GetCustomAttribute <MessageContractAttribute>(); Debug.Assert(messageContractAttribute != null, "operation.IsMessageContractRequest should be false if this is null"); var @namespace = parameterInfo.Namespace ?? operation.Contract.Namespace; if (messageContractAttribute.IsWrapped && !parameterType.GetMembersWithAttribute <MessageHeaderAttribute>().Any()) { //https://github.com/DigDes/SoapCore/issues/385 if (operation.DispatchMethod.GetCustomAttribute <XmlSerializerFormatAttribute>()?.Style == OperationFormatStyle.Rpc) { var importer = new SoapReflectionImporter(@namespace); var map = new XmlReflectionMember { IsReturnValue = false, MemberName = parameterInfo.Name, MemberType = parameterType }; var mapping = importer.ImportMembersMapping(parameterInfo.Name, @namespace, new[] { map }, false, true); var serializer = XmlSerializer.FromMappings(new[] { mapping })[0]; var value = serializer.Deserialize(xmlReader); if (value is object[] o && o.Length > 0) { arguments[parameterInfo.Index] = o[0]; } } else { // It's wrapped so we treat it like normal! arguments[parameterInfo.Index] = _serializerHelper.DeserializeInputParameter( xmlReader, parameterInfo.Parameter.ParameterType, parameterInfo.Name, @namespace, parameterInfo.Parameter.Member, serviceKnownTypes); } } else { var messageHeadersMembers = parameterType.GetPropertyOrFieldMembers() .Where(x => x.GetCustomAttribute <MessageHeaderAttribute>() != null) .Select(mi => new { MemberInfo = mi, MessageHeaderMemberAttribute = mi.GetCustomAttribute <MessageHeaderAttribute>() }).ToArray(); var wrapperObject = Activator.CreateInstance(parameterInfo.Parameter.ParameterType); for (var i = 0; i < requestMessage.Headers.Count; i++) { var header = requestMessage.Headers[i]; var member = messageHeadersMembers.FirstOrDefault(x => x.MessageHeaderMemberAttribute.Name == header.Name || x.MemberInfo.Name == header.Name); if (member != null) { var reader = requestMessage.Headers.GetReaderAtHeader(i); var value = _serializerHelper.DeserializeInputParameter( reader, member.MemberInfo.GetPropertyOrFieldType(), member.MessageHeaderMemberAttribute.Name ?? member.MemberInfo.Name, member.MessageHeaderMemberAttribute.Namespace ?? @namespace, member.MemberInfo, serviceKnownTypes); member.MemberInfo.SetValueToPropertyOrField(wrapperObject, value); } } // This object isn't a wrapper element, so we will hunt for the nested message body // member inside of it var messageBodyMembers = parameterType.GetPropertyOrFieldMembers().Where(x => x.GetCustomAttribute <MessageBodyMemberAttribute>() != null).Select(mi => new { Member = mi, MessageBodyMemberAttribute = mi.GetCustomAttribute <MessageBodyMemberAttribute>() }).OrderBy(x => x.MessageBodyMemberAttribute.Order); if (messageContractAttribute.IsWrapped) { xmlReader.Read(); } foreach (var messageBodyMember in messageBodyMembers) { var messageBodyMemberAttribute = messageBodyMember.MessageBodyMemberAttribute; var messageBodyMemberInfo = messageBodyMember.Member; var innerParameterName = messageBodyMemberAttribute.Name ?? messageBodyMemberInfo.Name; var innerParameterNs = messageBodyMemberAttribute.Namespace ?? @namespace; var innerParameterType = messageBodyMemberInfo.GetPropertyOrFieldType(); //xmlReader.MoveToStartElement(innerParameterName, innerParameterNs); var innerParameter = _serializerHelper.DeserializeInputParameter( xmlReader, innerParameterType, innerParameterName, innerParameterNs, parameterInfo.Parameter.Member, serviceKnownTypes); messageBodyMemberInfo.SetValueToPropertyOrField(wrapperObject, innerParameter); } arguments[parameterInfo.Index] = wrapperObject; } } foreach (var parameterInfo in operation.OutParameters) { if (arguments[parameterInfo.Index] != null) { // do not overwrite input ref parameters continue; } if (parameterInfo.Parameter.ParameterType.Name == "Guid&") { arguments[parameterInfo.Index] = Guid.Empty; } else if (parameterInfo.Parameter.ParameterType.Name == "String&" || parameterInfo.Parameter.ParameterType.GetElementType().IsArray) { arguments[parameterInfo.Index] = null; } else { var type = parameterInfo.Parameter.ParameterType.GetElementType(); arguments[parameterInfo.Index] = Activator.CreateInstance(type); } } return(arguments); }
internal static SoapReflectedMethod ReflectMethod(LogicalMethodInfo methodInfo, bool client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, string defaultNs) { SoapReflectedMethod method2; try { string str2; string str4; string key = methodInfo.GetKey(); SoapReflectedMethod method = new SoapReflectedMethod(); MethodAttribute attribute = new MethodAttribute(); object soapServiceAttribute = GetSoapServiceAttribute(methodInfo.DeclaringType); bool serviceDefaultIsEncoded = ServiceDefaultIsEncoded(soapServiceAttribute); object soapMethodAttribute = GetSoapMethodAttribute(methodInfo); if (soapMethodAttribute == null) { if (client) { return(null); } if (soapServiceAttribute is SoapRpcServiceAttribute) { SoapRpcMethodAttribute attribute2 = new SoapRpcMethodAttribute { Use = ((SoapRpcServiceAttribute)soapServiceAttribute).Use }; soapMethodAttribute = attribute2; } else if (soapServiceAttribute is SoapDocumentServiceAttribute) { SoapDocumentMethodAttribute attribute3 = new SoapDocumentMethodAttribute { Use = ((SoapDocumentServiceAttribute)soapServiceAttribute).Use }; soapMethodAttribute = attribute3; } else { soapMethodAttribute = new SoapDocumentMethodAttribute(); } } if (soapMethodAttribute is SoapRpcMethodAttribute) { SoapRpcMethodAttribute attribute4 = (SoapRpcMethodAttribute)soapMethodAttribute; method.rpc = true; method.use = attribute4.Use; method.oneWay = attribute4.OneWay; attribute.action = attribute4.Action; attribute.binding = attribute4.Binding; attribute.requestName = attribute4.RequestElementName; attribute.requestNs = attribute4.RequestNamespace; attribute.responseName = attribute4.ResponseElementName; attribute.responseNs = attribute4.ResponseNamespace; } else { SoapDocumentMethodAttribute attribute5 = (SoapDocumentMethodAttribute)soapMethodAttribute; method.rpc = false; method.use = attribute5.Use; method.paramStyle = attribute5.ParameterStyle; method.oneWay = attribute5.OneWay; attribute.action = attribute5.Action; attribute.binding = attribute5.Binding; attribute.requestName = attribute5.RequestElementName; attribute.requestNs = attribute5.RequestNamespace; attribute.responseName = attribute5.ResponseElementName; attribute.responseNs = attribute5.ResponseNamespace; if (method.use == SoapBindingUse.Default) { if (soapServiceAttribute is SoapDocumentServiceAttribute) { method.use = ((SoapDocumentServiceAttribute)soapServiceAttribute).Use; } if (method.use == SoapBindingUse.Default) { method.use = SoapBindingUse.Literal; } } if (method.paramStyle == SoapParameterStyle.Default) { if (soapServiceAttribute is SoapDocumentServiceAttribute) { method.paramStyle = ((SoapDocumentServiceAttribute)soapServiceAttribute).ParameterStyle; } if (method.paramStyle == SoapParameterStyle.Default) { method.paramStyle = SoapParameterStyle.Wrapped; } } } if (attribute.binding.Length > 0) { if (client) { throw new InvalidOperationException(System.Web.Services.Res.GetString("WebInvalidBindingPlacement", new object[] { soapMethodAttribute.GetType().Name })); } method.binding = WebServiceBindingReflector.GetAttribute(methodInfo, attribute.binding); } WebMethodAttribute methodAttribute = methodInfo.MethodAttribute; method.name = methodAttribute.MessageName; if (method.name.Length == 0) { method.name = methodInfo.Name; } if (method.rpc) { str2 = ((attribute.requestName.Length == 0) || !client) ? methodInfo.Name : attribute.requestName; } else { str2 = (attribute.requestName.Length == 0) ? method.name : attribute.requestName; } string requestNs = attribute.requestNs; if (requestNs == null) { if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0)) { requestNs = method.binding.Namespace; } else { requestNs = defaultNs; } } if (method.rpc && (method.use != SoapBindingUse.Encoded)) { str4 = methodInfo.Name + "Response"; } else { str4 = (attribute.responseName.Length == 0) ? (method.name + "Response") : attribute.responseName; } string responseNs = attribute.responseNs; if (responseNs == null) { if (((method.binding != null) && (method.binding.Namespace != null)) && (method.binding.Namespace.Length != 0)) { responseNs = method.binding.Namespace; } else { responseNs = defaultNs; } } SoapParameterInfo[] infoArray = ReflectParameters(methodInfo.InParameters, requestNs); SoapParameterInfo[] infoArray2 = ReflectParameters(methodInfo.OutParameters, responseNs); method.action = attribute.action; if (method.action == null) { method.action = GetDefaultAction(defaultNs, methodInfo); } method.methodInfo = methodInfo; if (method.oneWay) { if (infoArray2.Length > 0) { throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayOutParameters"), "methodInfo"); } if (methodInfo.ReturnType != typeof(void)) { throw new ArgumentException(System.Web.Services.Res.GetString("WebOneWayReturnValue"), "methodInfo"); } } XmlReflectionMember[] members = new XmlReflectionMember[infoArray.Length]; for (int i = 0; i < members.Length; i++) { SoapParameterInfo info = infoArray[i]; XmlReflectionMember member = new XmlReflectionMember { MemberName = info.parameterInfo.Name, MemberType = info.parameterInfo.ParameterType }; if (member.MemberType.IsByRef) { member.MemberType = member.MemberType.GetElementType(); } member.XmlAttributes = info.xmlAttributes; member.SoapAttributes = info.soapAttributes; members[i] = member; } method.requestMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str2, requestNs, attribute.requestNs == null, members, true, false, key, client); if (((GetSoapServiceRoutingStyle(soapServiceAttribute) == SoapServiceRoutingStyle.RequestElement) && (method.paramStyle == SoapParameterStyle.Bare)) && (method.requestMappings.Count != 1)) { throw new ArgumentException(System.Web.Services.Res.GetString("WhenUsingAMessageStyleOfParametersAsDocument0"), "methodInfo"); } string name = ""; string ns = ""; if (method.paramStyle == SoapParameterStyle.Bare) { if (method.requestMappings.Count == 1) { name = method.requestMappings[0].XsdElementName; ns = method.requestMappings[0].Namespace; } } else { name = method.requestMappings.XsdElementName; ns = method.requestMappings.Namespace; } method.requestElementName = new XmlQualifiedName(name, ns); if (!method.oneWay) { int num2 = infoArray2.Length; int num3 = 0; CodeIdentifiers identifiers = null; if (methodInfo.ReturnType != typeof(void)) { num2++; num3 = 1; identifiers = new CodeIdentifiers(); } members = new XmlReflectionMember[num2]; for (int m = 0; m < infoArray2.Length; m++) { SoapParameterInfo info2 = infoArray2[m]; XmlReflectionMember member2 = new XmlReflectionMember { MemberName = info2.parameterInfo.Name, MemberType = info2.parameterInfo.ParameterType }; if (member2.MemberType.IsByRef) { member2.MemberType = member2.MemberType.GetElementType(); } member2.XmlAttributes = info2.xmlAttributes; member2.SoapAttributes = info2.soapAttributes; members[num3++] = member2; if (identifiers != null) { identifiers.Add(member2.MemberName, null); } } if (methodInfo.ReturnType != typeof(void)) { XmlReflectionMember member3 = new XmlReflectionMember { MemberName = identifiers.MakeUnique(method.name + "Result"), MemberType = methodInfo.ReturnType, IsReturnValue = true, XmlAttributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider) }; member3.XmlAttributes.XmlRoot = null; member3.SoapAttributes = new SoapAttributes(methodInfo.ReturnTypeCustomAttributeProvider); members[0] = member3; } method.responseMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, method.rpc, method.use, method.paramStyle, str4, responseNs, attribute.responseNs == null, members, false, false, key + ":Response", !client); } SoapExtensionAttribute[] customAttributes = (SoapExtensionAttribute[])methodInfo.GetCustomAttributes(typeof(SoapExtensionAttribute)); method.extensions = new SoapReflectedExtension[customAttributes.Length]; for (int j = 0; j < customAttributes.Length; j++) { method.extensions[j] = new SoapReflectedExtension(customAttributes[j].ExtensionType, customAttributes[j]); } Array.Sort <SoapReflectedExtension>(method.extensions); SoapHeaderAttribute[] array = (SoapHeaderAttribute[])methodInfo.GetCustomAttributes(typeof(SoapHeaderAttribute)); Array.Sort(array, new SoapHeaderAttributeComparer()); Hashtable hashtable = new Hashtable(); method.headers = new SoapReflectedHeader[array.Length]; int num6 = 0; int length = method.headers.Length; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); for (int k = 0; k < method.headers.Length; k++) { SoapHeaderAttribute attribute7 = array[k]; SoapReflectedHeader header = new SoapReflectedHeader(); Type declaringType = methodInfo.DeclaringType; header.memberInfo = declaringType.GetField(attribute7.MemberName); if (header.memberInfo != null) { header.headerType = ((FieldInfo)header.memberInfo).FieldType; } else { header.memberInfo = declaringType.GetProperty(attribute7.MemberName); if (header.memberInfo == null) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderMissing"); } header.headerType = ((PropertyInfo)header.memberInfo).PropertyType; } if (header.headerType.IsArray) { header.headerType = header.headerType.GetElementType(); header.repeats = true; if ((header.headerType != typeof(SoapUnknownHeader)) && (header.headerType != typeof(SoapHeader))) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType"); } } if (MemberHelper.IsStatic(header.memberInfo)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderStatic"); } if (!MemberHelper.CanRead(header.memberInfo)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderRead"); } if (!MemberHelper.CanWrite(header.memberInfo)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderWrite"); } if (!typeof(SoapHeader).IsAssignableFrom(header.headerType)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderType"); } SoapHeaderDirection direction = attribute7.Direction; if (method.oneWay && ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0)) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebHeaderOneWayOut"); } if (hashtable.Contains(header.headerType)) { SoapHeaderDirection direction2 = (SoapHeaderDirection)hashtable[header.headerType]; if ((direction2 & direction) != 0) { throw HeaderException(attribute7.MemberName, methodInfo.DeclaringType, "WebMultiplyDeclaredHeaderTypes"); } hashtable[header.headerType] = direction | direction2; } else { hashtable[header.headerType] = direction; } if ((header.headerType != typeof(SoapHeader)) && (header.headerType != typeof(SoapUnknownHeader))) { XmlReflectionMember member4 = new XmlReflectionMember { MemberName = header.headerType.Name, MemberType = header.headerType }; XmlAttributes attributes = new XmlAttributes(header.headerType); if (attributes.XmlRoot != null) { member4.XmlAttributes = new XmlAttributes(); XmlElementAttribute attribute8 = new XmlElementAttribute { ElementName = attributes.XmlRoot.ElementName, Namespace = attributes.XmlRoot.Namespace }; member4.XmlAttributes.XmlElements.Add(attribute8); } member4.OverrideIsNullable = true; if ((direction & SoapHeaderDirection.In) != 0) { list.Add(member4); } if ((direction & (SoapHeaderDirection.Fault | SoapHeaderDirection.Out)) != 0) { list2.Add(member4); } header.custom = true; } header.direction = direction; if (!header.custom) { method.headers[--length] = header; } else { method.headers[num6++] = header; } } method.inHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str2 + "InHeaders", defaultNs, true, (XmlReflectionMember[])list.ToArray(typeof(XmlReflectionMember)), false, true, key + ":InHeaders", client); if (!method.oneWay) { method.outHeaderMappings = ImportMembersMapping(xmlImporter, soapImporter, serviceDefaultIsEncoded, false, method.use, SoapParameterStyle.Bare, str4 + "OutHeaders", defaultNs, true, (XmlReflectionMember[])list2.ToArray(typeof(XmlReflectionMember)), false, true, key + ":OutHeaders", !client); } method2 = method; } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } throw new InvalidOperationException(System.Web.Services.Res.GetString("WebReflectionErrorMethod", new object[] { methodInfo.DeclaringType.Name, methodInfo.Name }), exception); } return(method2); }