SoapBindingUse GetMessageEncoding(MessageBinding mb) { SoapBodyBinding sbb = mb.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding; if (sbb == null) { if (mb is InputBinding) { return(SoapBindingUse.Encoded); } else { return(SoapBindingUse.Literal); } } else if (sbb.Use == SoapBindingUse.Encoded) { return(SoapBindingUse.Encoded); } else { return(SoapBindingUse.Literal); } }
static WsdlNS.SoapBodyBinding ConvertSoapBodyBinding(WsdlNS.SoapBodyBinding src, EnvelopeVersion version) { if (version == EnvelopeVersion.None) { return(null); } EnvelopeVersion srcVersion = GetBindingVersion <WsdlNS.Soap12BodyBinding>(src); if (srcVersion == version) { return(src); } WsdlNS.SoapBodyBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12BodyBinding() : new WsdlNS.SoapBodyBinding(); if (src != null) { if (XmlSerializerOperationFormatter.GetEncoding(srcVersion) == src.Encoding) { dest.Encoding = XmlSerializerOperationFormatter.GetEncoding(version); } dest.Encoding = XmlSerializerOperationFormatter.GetEncoding(version); dest.Namespace = src.Namespace; dest.Parts = src.Parts; dest.PartsString = src.PartsString; dest.Use = src.Use; dest.Required = src.Required; } return(dest); }
void AddOperationMsgBindings(SoapMethodStubInfo method, MessageBinding msg) { SoapBodyBinding sbbo = CreateSoapBodyBinding(); msg.Extensions.Add(sbbo); sbbo.Use = method.Use; if (method.Use == SoapBindingUse.Encoded) { sbbo.Namespace = ReflectionContext.ServiceDescription.TargetNamespace; sbbo.Encoding = EncodingNS; } }
protected virtual SoapBodyBinding CreateSoapBodyBinding(SoapBindingUse use, string ns) { SoapBodyBinding soapBodyBinding = new SoapBodyBinding(); soapBodyBinding.Use = use; if (use == SoapBindingUse.Encoded) { soapBodyBinding.Encoding = Soap.Encoding; } soapBodyBinding.Namespace = ns; return(soapBodyBinding); }
static void TestSoapBody(WS.SoapBodyBinding soap, bool soap12, TestLabel label) { label.EnterScope("soap-body"); var type = soap12 ? typeof(WS.Soap12BodyBinding) : typeof(WS.SoapBodyBinding); Assert.That(soap.GetType(), Is.EqualTo(type), label.Get()); Assert.That(soap.Encoding, Is.Empty, label.Get()); Assert.That(soap.Namespace, Is.Empty, label.Get()); Assert.That(soap.Parts, Is.Null, label.Get()); Assert.That(soap.Use, Is.EqualTo(WS.SoapBindingUse.Literal), label.Get()); label.LeaveScope(); }
protected virtual SoapBodyBinding CreateSoapBodyBinding(SoapBindingUse use, string ns) { SoapBodyBinding binding = new SoapBodyBinding { Use = use }; if (use == SoapBindingUse.Encoded) { binding.Encoding = "http://schemas.xmlsoap.org/soap/encoding/"; } binding.Namespace = ns; return(binding); }
static WsdlNS.SoapBodyBinding CreateSoapBodyBinding(EnvelopeVersion version, WsdlNS.MessageBinding wsdlMessageBinding) { WsdlNS.SoapBodyBinding soapBodyBinding = null; if (version == EnvelopeVersion.Soap12) { soapBodyBinding = new WsdlNS.Soap12BodyBinding(); } else if (version == EnvelopeVersion.Soap11) { soapBodyBinding = new WsdlNS.SoapBodyBinding(); } Fx.Assert(soapBodyBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class"); wsdlMessageBinding.Extensions.Add(soapBodyBinding); return(soapBodyBinding); }
internal static WsdlNS.SoapBodyBinding GetOrCreateSoapBodyBinding(WsdlEndpointConversionContext endpointContext, WsdlNS.MessageBinding wsdlMessageBinding, WsdlExporter exporter) { if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None) { return(null); } WsdlNS.SoapBodyBinding existingSoapBodyBinding = GetSoapBodyBinding(endpointContext, wsdlMessageBinding); EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding); if (existingSoapBodyBinding != null) { return(existingSoapBodyBinding); } WsdlNS.SoapBodyBinding soapBodyBinding = CreateSoapBodyBinding(version, wsdlMessageBinding); return(soapBodyBinding); }
void AddMessageSchema(XmlSchemas schemas, MessageBinding mb, Message msg) { foreach (MessagePart part in msg.Parts) { if (part.Element != XmlQualifiedName.Empty) { AddIncludingSchema(schemas, part.Element.Namespace); } else if (part.Type != XmlQualifiedName.Empty) { AddIncludingSchema(schemas, part.Type.Namespace); } } SoapBodyBinding sbb = mb.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding; if (sbb != null) { AddIncludingSchema(schemas, sbb.Namespace); } }
internal static bool ConvertSoapMessageBinding(ref object src, EnvelopeVersion version) { WsdlNS.SoapBodyBinding body = src as WsdlNS.SoapBodyBinding; if (body != null) { src = ConvertSoapBodyBinding(body, version); return(true); } WsdlNS.SoapHeaderBinding header = src as WsdlNS.SoapHeaderBinding; if (header != null) { src = ConvertSoapHeaderBinding(header, version); return(true); } WsdlNS.SoapFaultBinding fault = src as WsdlNS.SoapFaultBinding; if (fault != null) { src = ConvertSoapFaultBinding(fault, version); return(true); } XmlElement element = src as XmlElement; if (element != null) { if (IsSoapFaultBinding(element)) { src = ConvertSoapFaultBinding(element, version); return(true); } } return(src == null); // "match" only if nothing passed in }
LiteralType GetLiteralBindingType(Binding b) { SoapBinding sb = (SoapBinding)b.Extensions.Find(typeof(SoapBinding)); SoapBindingStyle style = (sb != null) ? sb.Style : SoapBindingStyle.Document; if (style == SoapBindingStyle.Default) { style = SoapBindingStyle.Document; } foreach (OperationBinding ob in b.Operations) { SoapOperationBinding sob = (SoapOperationBinding)ob.Extensions.Find(typeof(SoapOperationBinding)); if (sob.Style != SoapBindingStyle.Default && sob.Style != style) { return(LiteralType.Inconsistent); } if (ob.Input != null) { SoapBodyBinding sbb = (SoapBodyBinding)ob.Input.Extensions.Find(typeof(SoapBodyBinding)); if (sbb != null && sbb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } SoapFaultBinding sfb = (SoapFaultBinding)ob.Input.Extensions.Find(typeof(SoapFaultBinding)); if (sfb != null && sfb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } SoapHeaderBinding shb = (SoapHeaderBinding)ob.Input.Extensions.Find(typeof(SoapHeaderBinding)); if (shb != null && shb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding)ob.Input.Extensions.Find(typeof(SoapHeaderFaultBinding)); if (shfb != null && shfb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } } if (ob.Output != null) { SoapBodyBinding sbb = (SoapBodyBinding)ob.Output.Extensions.Find(typeof(SoapBodyBinding)); if (sbb != null && sbb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } SoapFaultBinding sfb = (SoapFaultBinding)ob.Input.Extensions.Find(typeof(SoapFaultBinding)); if (sfb != null && sfb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } SoapHeaderBinding shb = (SoapHeaderBinding)ob.Input.Extensions.Find(typeof(SoapHeaderBinding)); if (shb != null && shb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding)ob.Input.Extensions.Find(typeof(SoapHeaderFaultBinding)); if (shfb != null && shfb.Use != SoapBindingUse.Literal) { return(LiteralType.NotLiteral); } } } if (style == SoapBindingStyle.Document) { return(LiteralType.Document); } else { return(LiteralType.Rpc); } }
void CheckMessageBinding(ConformanceCheckContext ctx, Hashtable portParts, MessageBinding value) { SoapBodyBinding sbb = (SoapBodyBinding)value.Extensions.Find(typeof(SoapBodyBinding)); Message msg = FindMessage(ctx, value); LiteralType bt = GetLiteralBindingType(value.OperationBinding.Binding); if (sbb != null) { if (bt == LiteralType.Document) { if (sbb.Parts != null && sbb.Parts.Length > 1) { ctx.ReportRuleViolation(value, BasicProfileRules.R2201); } if (sbb.Parts == null) { if (msg.Parts != null && msg.Parts.Count > 1) { ctx.ReportRuleViolation(value, BasicProfileRules.R2210); } if (msg.Parts.Count == 1) { portParts.Remove(msg.Parts[0]); } } else { if (sbb.Parts.Length == 0 && msg.Parts.Count == 1) { portParts.Remove(msg.Parts[0]); } else { foreach (string part in sbb.Parts) { MessagePart mp = msg.FindPartByName(part); portParts.Remove(mp); if (!mp.DefinedByElement) { ctx.ReportRuleViolation(value, BasicProfileRules.R2204); } } } } } else if (bt == LiteralType.Rpc) { if (sbb.Parts != null) { foreach (string part in sbb.Parts) { MessagePart mp = msg.FindPartByName(part); portParts.Remove(mp); if (!mp.DefinedByType) { ctx.ReportRuleViolation(value, BasicProfileRules.R2203); } } } } } SoapHeaderBinding shb = (SoapHeaderBinding)value.Extensions.Find(typeof(SoapHeaderBinding)); if (shb != null) { Message hm = ctx.Services.GetMessage(shb.Message); MessagePart mp = hm.FindPartByName(shb.Part); portParts.Remove(mp); if (mp != null && !mp.DefinedByElement) { ctx.ReportRuleViolation(value, BasicProfileRules.R2205); } } SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding)value.Extensions.Find(typeof(SoapHeaderFaultBinding)); if (shfb != null) { Message hm = ctx.Services.GetMessage(shfb.Message); MessagePart mp = hm.FindPartByName(shfb.Part); portParts.Remove(mp); if (mp != null && !mp.DefinedByElement) { ctx.ReportRuleViolation(value, BasicProfileRules.R2205); } } // TODO: SoapFaultBinding ?? }
private void Write99_SoapBodyBinding(string n, string ns, SoapBodyBinding o, bool isNullable, bool needType) { if (o == null) { if (isNullable) { base.WriteNullTagLiteral(n, ns); } } else { if (!needType && !(o.GetType() == typeof(SoapBodyBinding))) { throw base.CreateUnknownTypeException(o); } base.WriteStartElement(n, ns, o, false, null); if (needType) { base.WriteXsiType("SoapBodyBinding", "http://schemas.xmlsoap.org/wsdl/soap/"); } if (o.Required) { base.WriteAttribute("required", "http://schemas.xmlsoap.org/wsdl/", XmlConvert.ToString(o.Required)); } if (o.Use != SoapBindingUse.Default) { base.WriteAttribute("use", "", this.Write98_SoapBindingUse(o.Use)); } if ((o.Namespace != null) && (o.Namespace.Length != 0)) { base.WriteAttribute("namespace", "", o.Namespace); } if ((o.Encoding != null) && (o.Encoding.Length != 0)) { base.WriteAttribute("encodingStyle", "", o.Encoding); } base.WriteAttribute("parts", "", o.PartsString); base.WriteEndElement(o); } }
private static SoapBodyBinding FindSoapBodyBinding(bool input, ServiceDescriptionFormatExtensionCollection extensions, BasicProfileViolationCollection violations, bool documentBinding, string operationName, string bindingName, string bindingNs) { SoapBodyBinding binding = null; for (int i = 0; i < extensions.Count; i++) { object item = extensions[i]; string uriString = null; bool flag = false; bool flag2 = false; if (item is SoapBodyBinding) { flag = true; binding = (SoapBodyBinding)item; uriString = binding.Namespace; flag2 = binding.Use == SoapBindingUse.Encoded; } else if (item is SoapHeaderBinding) { flag = true; SoapHeaderBinding binding2 = (SoapHeaderBinding)item; uriString = binding2.Namespace; flag2 = binding2.Use == SoapBindingUse.Encoded; if (!flag2 && ((binding2.Part == null) || (binding2.Part.Length == 0))) { violations.Add("R2720", MessageString(binding2, operationName, bindingName, bindingNs, input, null)); } if (binding2.Fault != null) { flag2 |= binding2.Fault.Use == SoapBindingUse.Encoded; if (!flag2) { if ((binding2.Fault.Part == null) || (binding2.Fault.Part.Length == 0)) { violations.Add("R2720", MessageString(binding2.Fault, operationName, bindingName, bindingNs, input, null)); } if ((binding2.Fault.Namespace != null) && (binding2.Fault.Namespace.Length > 0)) { violations.Add(documentBinding ? "R2716" : "R2726", MessageString(item, operationName, bindingName, bindingNs, input, null)); } } } } if (flag2) { violations.Add("R2706", MessageString(item, operationName, bindingName, bindingNs, input, null)); } else if (flag) { if ((uriString == null) || (uriString.Length == 0)) { if (!documentBinding && (item is SoapBodyBinding)) { violations.Add("R2717", MessageString(item, operationName, bindingName, bindingNs, input, null)); } } else if (documentBinding || !(item is SoapBodyBinding)) { violations.Add(documentBinding ? "R2716" : "R2726", MessageString(item, operationName, bindingName, bindingNs, input, null)); } else { Uri uri; if (!Uri.TryCreate(uriString, UriKind.Absolute, out uri)) { violations.Add("R2717", MessageString(item, operationName, bindingName, bindingNs, input, System.Web.Services.Res.GetString("UriValueRelative", new object[] { uriString }))); } } } } return(binding); }
MessagePart[] GetMessageParts(Message message, SoapBodyBinding soapBodyBinding) { MessagePart[] parts; if (soapBodyBinding.Parts == null) { parts = new MessagePart[message.Parts.Count]; message.Parts.CopyTo(parts, 0); } else { parts = message.FindPartsByName(soapBodyBinding.Parts); } return parts; }
private XmlMembersMapping ImportMessage(string messageName, MessagePart[] parts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle, bool wrapped) { if (soapBodyBinding.Use == SoapBindingUse.Encoded) { return this.ImportEncodedMessage(messageName, parts, soapBodyBinding, wrapped); } return this.ImportLiteralMessage(messageName, parts, soapBodyBinding, soapBindingStyle, wrapped); }
protected virtual SoapBodyBinding CreateSoapBodyBinding(SoapBindingUse use, string ns) { SoapBodyBinding binding = new SoapBodyBinding { Use = use }; if (use == SoapBindingUse.Encoded) { binding.Encoding = "http://schemas.xmlsoap.org/soap/encoding/"; } binding.Namespace = ns; return binding; }
private XmlMembersMapping ImportEncodedMessage(string messageName, MessagePart[] parts, SoapBodyBinding soapBodyBinding, bool wrapped) { XmlMembersMapping mapping; if (wrapped) { SoapSchemaMember member = new SoapSchemaMember { MemberName = parts[0].Name, MemberType = parts[0].Type }; mapping = this.soapImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, member); } else { SoapSchemaMember[] members = new SoapSchemaMember[parts.Length]; for (int i = 0; i < members.Length; i++) { MessagePart part = parts[i]; members[i] = new SoapSchemaMember { MemberName = part.Name, MemberType = part.Type }; } mapping = this.soapImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, members); } this.soapMembers.Add(mapping); return mapping; }
private XmlMembersMapping ImportLiteralMessage(string messageName, MessagePart[] parts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle, bool wrapped) { XmlMembersMapping mapping; if (soapBindingStyle == SoapBindingStyle.Rpc) { SoapSchemaMember[] members = new SoapSchemaMember[parts.Length]; for (int i = 0; i < members.Length; i++) { MessagePart part = parts[i]; members[i] = new SoapSchemaMember { MemberName = part.Name, MemberType = part.Type }; } mapping = this.xmlImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, members); } else if (wrapped) { mapping = this.xmlImporter.ImportMembersMapping(parts[0].Element); } else { if ((parts.Length == 1) && !parts[0].Type.IsEmpty) { mapping = this.xmlImporter.ImportAnyType(parts[0].Type, parts[0].Name); this.xmlMembers.Add(mapping); return mapping; } XmlQualifiedName[] names = new XmlQualifiedName[parts.Length]; for (int j = 0; j < parts.Length; j++) { names[j] = parts[j].Element; } mapping = this.xmlImporter.ImportMembersMapping(names); } this.xmlMembers.Add(mapping); return mapping; }
private MessagePart[] GetMessageParts(Message message, SoapBodyBinding soapBodyBinding) { if (soapBodyBinding.Parts == null) { MessagePart[] array = new MessagePart[message.Parts.Count]; message.Parts.CopyTo(array, 0); return array; } return message.FindPartsByName(soapBodyBinding.Parts); }
private bool CheckMessageStyles(string messageName, MessagePart[] parts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle, out bool hasWrapper) { hasWrapper = false; if (soapBodyBinding.Use == SoapBindingUse.Default) { soapBodyBinding.Use = SoapBindingUse.Literal; } if (soapBodyBinding.Use == SoapBindingUse.Literal) { if (soapBindingStyle == SoapBindingStyle.Rpc) { foreach (MessagePart part in parts) { if (!part.Element.IsEmpty) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("EachMessagePartInRpcUseLiteralMessageMustSpecify0")); return false; } } return true; } if ((parts.Length == 1) && !parts[0].Type.IsEmpty) { if (!parts[0].Element.IsEmpty) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("SpecifyingATypeForUseLiteralMessagesIs0")); return false; } if (this.xmlImporter.ImportAnyType(parts[0].Type, parts[0].Name) == null) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("SpecifyingATypeForUseLiteralMessagesIsAny", new object[] { parts[0].Type.Name, parts[0].Type.Namespace })); return false; } return true; } foreach (MessagePart part2 in parts) { if (!part2.Type.IsEmpty) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("SpecifyingATypeForUseLiteralMessagesIs0")); return false; } if (part2.Element.IsEmpty) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("EachMessagePartInAUseLiteralMessageMustSpecify0")); return false; } } } else if (soapBodyBinding.Use == SoapBindingUse.Encoded) { if (!this.IsSoapEncodingPresent(soapBodyBinding.Encoding)) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("TheEncodingIsNotSupported1", new object[] { soapBodyBinding.Encoding })); return false; } foreach (MessagePart part3 in parts) { if (!part3.Element.IsEmpty) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("SpecifyingAnElementForUseEncodedMessageParts0")); return false; } if (part3.Type.IsEmpty) { base.UnsupportedOperationBindingWarning(System.Web.Services.Res.GetString("EachMessagePartInAnUseEncodedMessageMustSpecify0")); return false; } } } if (soapBindingStyle == SoapBindingStyle.Rpc) { return true; } if (soapBindingStyle == SoapBindingStyle.Document) { hasWrapper = (parts.Length == 1) && (string.Compare(parts[0].Name, "parameters", StringComparison.Ordinal) == 0); return true; } return false; }
private void FindUse(Operation operation, ServiceDescription description, string messageName, ref bool isEncoded, ref bool isLiteral) { string targetNamespace = description.TargetNamespace; foreach (Binding binding in description.Bindings) { if (operation != null && !new XmlQualifiedName(operation.PortType.Name, targetNamespace).Equals(binding.Type)) { continue; } foreach (OperationBinding bindingOperation in binding.Operations) { if (bindingOperation.Input != null) { foreach (object extension in bindingOperation.Input.Extensions) { if (operation != null) { SoapBodyBinding body = extension as SoapBodyBinding; if (body != null && operation.IsBoundBy(bindingOperation)) { if (body.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (body.Use == SoapBindingUse.Literal) { isLiteral = true; } } } else { SoapHeaderBinding header = extension as SoapHeaderBinding; if (header != null && header.Message.Name == messageName) { if (header.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (header.Use == SoapBindingUse.Literal) { isLiteral = true; } } } } } if (bindingOperation.Output != null) { foreach (object extension in bindingOperation.Output.Extensions) { if (operation != null) { if (operation.IsBoundBy(bindingOperation)) { SoapBodyBinding body = extension as SoapBodyBinding; if (body != null) { if (body.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (body.Use == SoapBindingUse.Literal) { isLiteral = true; } } else if (extension is MimeXmlBinding) { isLiteral = true; } } } else { SoapHeaderBinding header = extension as SoapHeaderBinding; if (header != null && header.Message.Name == messageName) { if (header.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (header.Use == SoapBindingUse.Literal) { isLiteral = true; } } } } } } } }
void WriteBody(XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style) { Message msg = descriptions.GetMessage(opm.Message); if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters") { MessagePart part = msg.Parts[0]; if (part.Element == XmlQualifiedName.Empty) WriteTypeSample(xtw, part.Type); else WriteRootElementSample(xtw, part.Element); } else { string elemName = oper.Name; string ns = ""; if (opm is OperationOutput) elemName += "Response"; if (style == SoapBindingStyle.Rpc) { xtw.WriteStartElement(elemName, sbb.Namespace); ns = sbb.Namespace; } foreach (MessagePart part in msg.Parts) { if (part.Element == XmlQualifiedName.Empty) { XmlSchemaElement elem = new XmlSchemaElement(); elem.SchemaTypeName = part.Type; elem.Name = part.Name; WriteElementSample(xtw, ns, elem); } else WriteRootElementSample(xtw, part.Element); } if (style == SoapBindingStyle.Rpc) xtw.WriteEndElement(); } WriteQueuedTypeSamples(xtw); }
private void FindUse(Operation operation, ServiceDescription description, string messageName, ref bool isEncoded, ref bool isLiteral) { string targetNamespace = description.TargetNamespace; foreach (Binding binding in description.Bindings) { if ((operation == null) || new XmlQualifiedName(operation.PortType.Name, targetNamespace).Equals(binding.Type)) { foreach (OperationBinding binding2 in binding.Operations) { if (binding2.Input != null) { foreach (object obj2 in binding2.Input.Extensions) { if (operation != null) { SoapBodyBinding binding3 = obj2 as SoapBodyBinding; if ((binding3 != null) && operation.IsBoundBy(binding2)) { if (binding3.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (binding3.Use == SoapBindingUse.Literal) { isLiteral = true; } } } else { SoapHeaderBinding binding4 = obj2 as SoapHeaderBinding; if ((binding4 != null) && (binding4.Message.Name == messageName)) { if (binding4.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (binding4.Use == SoapBindingUse.Literal) { isLiteral = true; } } } } } if (binding2.Output != null) { foreach (object obj3 in binding2.Output.Extensions) { if (operation != null) { if (operation.IsBoundBy(binding2)) { SoapBodyBinding binding5 = obj3 as SoapBodyBinding; if (binding5 != null) { if (binding5.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (binding5.Use == SoapBindingUse.Literal) { isLiteral = true; } } else if (obj3 is MimeXmlBinding) { isLiteral = true; } } } else { SoapHeaderBinding binding6 = obj3 as SoapHeaderBinding; if ((binding6 != null) && (binding6.Message.Name == messageName)) { if (binding6.Use == SoapBindingUse.Encoded) { isEncoded = true; } else if (binding6.Use == SoapBindingUse.Literal) { isLiteral = true; } } } } } } } } }
public void InitializeSoapBodyBinding() { sbb = new SoapBodyBinding(); }
CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, SoapOperationBinding soapOper, SoapBodyBinding bodyBinding, XmlMembersMapping inputMembers, XmlMembersMapping outputMembers) { CodeIdentifiers pids = new CodeIdentifiers (); CodeMemberMethod method = new CodeMemberMethod (); CodeMemberMethod methodBegin = new CodeMemberMethod (); CodeMemberMethod methodEnd = new CodeMemberMethod (); method.Attributes = MemberAttributes.Public | MemberAttributes.Final; methodBegin.Attributes = MemberAttributes.Public | MemberAttributes.Final; methodEnd.Attributes = MemberAttributes.Public | MemberAttributes.Final; SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style; // Find unique names for temporary variables for (int n=0; n<inputMembers.Count; n++) pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]); if (outputMembers != null) for (int n=0; n<outputMembers.Count; n++) pids.AddUnique (outputMembers[n].MemberName, outputMembers[n]); string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult"); string varResults = pids.AddUnique ("results","results"); string varCallback = pids.AddUnique ("callback","callback"); string varAsyncState = pids.AddUnique ("asyncState","asyncState"); string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method); method.Name = CodeIdentifier.MakeValid(Operation.Name); if (method.Name == ClassName) method.Name += "1"; methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + method.Name),method); methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + method.Name),method); method.ReturnType = new CodeTypeReference (typeof(void)); methodEnd.ReturnType = new CodeTypeReference (typeof(void)); methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult)); CodeExpression[] paramArray = new CodeExpression [inputMembers.Count]; CodeParameterDeclarationExpression[] outParams = new CodeParameterDeclarationExpression [outputMembers != null ? outputMembers.Count : 0]; for (int n=0; n<inputMembers.Count; n++) { CodeParameterDeclarationExpression param = GenerateParameter (inputMembers[n], FieldDirection.In); method.Parameters.Add (param); GenerateMemberAttributes (inputMembers, inputMembers[n], bodyBinding.Use, param); methodBegin.Parameters.Add (GenerateParameter (inputMembers[n], FieldDirection.In)); paramArray [n] = new CodeVariableReferenceExpression (param.Name); } if (outputMembers != null) { bool hasReturn = false; for (int n=0; n<outputMembers.Count; n++) { CodeParameterDeclarationExpression cpd = GenerateParameter (outputMembers[n], FieldDirection.Out); outParams [n] = cpd; bool found = false; foreach (CodeParameterDeclarationExpression ip in method.Parameters) { if (ip.Name == cpd.Name && ip.Type.BaseType == cpd.Type.BaseType) { ip.Direction = FieldDirection.Ref; methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out)); found = true; break; } } if (found) continue; if (!hasReturn) { hasReturn = true; method.ReturnType = cpd.Type; methodEnd.ReturnType = cpd.Type; GenerateReturnAttributes (outputMembers, outputMembers[n], bodyBinding.Use, method); outParams [n] = null; continue; } method.Parameters.Add (cpd); GenerateMemberAttributes (outputMembers, outputMembers[n], bodyBinding.Use, cpd); methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out)); } } methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback)); methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState)); methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult)); // Array of input parameters CodeArrayCreateExpression methodParams; if (paramArray.Length > 0) methodParams = new CodeArrayCreateExpression (typeof(object), paramArray); else methodParams = new CodeArrayCreateExpression (typeof(object), 0); // Assignment of output parameters CodeStatementCollection outAssign = new CodeStatementCollection (); CodeVariableReferenceExpression arrVar = new CodeVariableReferenceExpression (varResults); for (int n=0; n<outParams.Length; n++) { CodeExpression index = new CodePrimitiveExpression (n); if (outParams[n] == null) { CodeExpression res = new CodeCastExpression (method.ReturnType, new CodeArrayIndexerExpression (arrVar, index)); outAssign.Add (new CodeMethodReturnStatement (res)); } else { CodeExpression res = new CodeCastExpression (outParams[n].Type, new CodeArrayIndexerExpression (arrVar, index)); CodeExpression var = new CodeVariableReferenceExpression (outParams[n].Name); outAssign.Insert (0, new CodeAssignStatement (var, res)); } } if (Style == ServiceDescriptionImportStyle.Client) { // Invoke call CodeThisReferenceExpression ethis = new CodeThisReferenceExpression(); CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName); CodeMethodInvokeExpression inv; CodeVariableDeclarationStatement dec; inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, methodParams); if (outputMembers != null && outputMembers.Count > 0) { dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv); method.Statements.Add (dec); method.Statements.AddRange (outAssign); } else method.Statements.Add (inv); // Begin Invoke Call CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback); CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState); inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, methodParams, expCallb, expAsyncs); methodBegin.Statements.Add (new CodeMethodReturnStatement (inv)); // End Invoke call CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult); inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr); if (outputMembers != null && outputMembers.Count > 0) { dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv); methodEnd.Statements.Add (dec); methodEnd.Statements.AddRange (outAssign); } else methodEnd.Statements.Add (inv); } else { method.Attributes = MemberAttributes.Public | MemberAttributes.Abstract; } // Attributes ImportHeaders (method); CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebMethodAttribute"); if (messageName != method.Name) att.Arguments.Add (GetArg ("MessageName",messageName)); AddCustomAttribute (method, att, (Style == ServiceDescriptionImportStyle.Server)); if (style == SoapBindingStyle.Rpc) { att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapRpcMethodAttribute"); att.Arguments.Add (GetArg (soapOper.SoapAction)); if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName)); if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName)); att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace)); if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace)); if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true)); } else { if (outputMembers != null && (inputMembers.ElementName == "" && outputMembers.ElementName != "" || inputMembers.ElementName != "" && outputMembers.ElementName == "")) throw new InvalidOperationException ("Parameter style is not the same for the input message and output message"); att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapDocumentMethodAttribute"); att.Arguments.Add (GetArg (soapOper.SoapAction)); if (inputMembers.ElementName != "") { if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName)); if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName)); att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace)); if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace)); att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Wrapped")); } else att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Bare")); if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true)); att.Arguments.Add (GetEnumArg ("Use", "System.Web.Services.Description.SoapBindingUse", bodyBinding.Use.ToString())); } AddCustomAttribute (method, att, true); CodeTypeDeclaration.Members.Add (method); if (Style == ServiceDescriptionImportStyle.Client) { CodeTypeDeclaration.Members.Add (methodBegin); CodeTypeDeclaration.Members.Add (methodEnd); } return method; }
private static object GetSoapBodyBinding(System.ServiceModel.Channels.Binding binding) { if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap11) { SoapBodyBinding soapBinding = new SoapBodyBinding(); soapBinding.Use = SoapBindingUse.Literal; return soapBinding; } else if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap12) { Soap12BodyBinding soap12Binding = new Soap12BodyBinding(); soap12Binding.Use = SoapBindingUse.Literal; return soap12Binding; } return null; }
void CreateOutputBinding (ServiceEndpoint endpoint, OperationBinding op_binding, MessageDescription sm_md) { var out_binding = new OutputBinding (); op_binding.Output = out_binding; var message_version = endpoint.Binding.MessageVersion ?? MessageVersion.None; if (message_version == MessageVersion.None) return; SoapBodyBinding soap_body_binding; if (message_version.Envelope == EnvelopeVersion.Soap11) { soap_body_binding = new SoapBodyBinding (); } else if (message_version.Envelope == EnvelopeVersion.Soap12) { soap_body_binding = new Soap12BodyBinding (); } else { throw new InvalidOperationException (); } soap_body_binding.Use = SoapBindingUse.Literal; out_binding.Extensions.Add (soap_body_binding); }
// returns false if we didn't like the message -- otherwise caller is safe to use body binding and binding style bool CheckMessageStyles(string messageName, MessagePart[] parts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle, out bool hasWrapper) { hasWrapper = false; if (soapBodyBinding.Use == SoapBindingUse.Default) { soapBodyBinding.Use = SoapBindingUse.Literal; } if (soapBodyBinding.Use == SoapBindingUse.Literal) { if (soapBindingStyle == SoapBindingStyle.Rpc) { foreach (MessagePart part in parts) { if (!part.Element.IsEmpty) { UnsupportedOperationBindingWarning(Res.GetString(Res.EachMessagePartInRpcUseLiteralMessageMustSpecify0)); return false; } } return true; } if (parts.Length == 1 && !parts[0].Type.IsEmpty) { // special top-level any case if (!parts[0].Element.IsEmpty) { UnsupportedOperationBindingWarning(Res.GetString(Res.SpecifyingATypeForUseLiteralMessagesIs0)); return false; } XmlMembersMapping membersMapping = xmlImporter.ImportAnyType(parts[0].Type, parts[0].Name); if (membersMapping == null) { UnsupportedOperationBindingWarning(Res.GetString(Res.SpecifyingATypeForUseLiteralMessagesIsAny, parts[0].Type.Name, parts[0].Type.Namespace)); return false; } return true; } else { foreach (MessagePart part in parts) { if (!part.Type.IsEmpty) { UnsupportedOperationBindingWarning(Res.GetString(Res.SpecifyingATypeForUseLiteralMessagesIs0)); return false; } if (part.Element.IsEmpty) { UnsupportedOperationBindingWarning(Res.GetString(Res.EachMessagePartInAUseLiteralMessageMustSpecify0)); return false; } } } } else if (soapBodyBinding.Use == SoapBindingUse.Encoded) { if (!IsSoapEncodingPresent(soapBodyBinding.Encoding)) { UnsupportedOperationBindingWarning(Res.GetString(Res.TheEncodingIsNotSupported1, soapBodyBinding.Encoding)); return false; } foreach (MessagePart part in parts) { if (!part.Element.IsEmpty) { UnsupportedOperationBindingWarning(Res.GetString(Res.SpecifyingAnElementForUseEncodedMessageParts0)); return false; } if (part.Type.IsEmpty) { UnsupportedOperationBindingWarning(Res.GetString(Res.EachMessagePartInAnUseEncodedMessageMustSpecify0)); return false; } } } if (soapBindingStyle == SoapBindingStyle.Rpc) { return true; } else if (soapBindingStyle == SoapBindingStyle.Document) { // NOTE, [....]. WSDL doesn't really let us figure out whether a document is // in fact a struct containing parameters, so we apply a little heuristic here // in order to produce the appropriate programming model. hasWrapper = (parts.Length == 1 && string.Compare(parts[0].Name, "parameters", StringComparison.Ordinal) == 0); return true; } return false; }
XmlMembersMapping ImportLiteralMessage(string messageName, MessagePart[] parts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle, bool wrapped) { XmlMembersMapping membersMapping; if (soapBindingStyle == SoapBindingStyle.Rpc) { SoapSchemaMember[] schemaMembers = new SoapSchemaMember[parts.Length]; for (int i = 0; i < schemaMembers.Length; i++) { MessagePart part = parts[i]; SoapSchemaMember schemaMember = new SoapSchemaMember(); schemaMember.MemberName = part.Name; schemaMember.MemberType = part.Type; schemaMembers[i] = schemaMember; } membersMapping = xmlImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, schemaMembers); } else if (wrapped) { membersMapping = xmlImporter.ImportMembersMapping(parts[0].Element); } else { if (parts.Length == 1 && !parts[0].Type.IsEmpty) { // special case for <any> at root // we know this will work because we tried it earlier in CheckMessageStyles. membersMapping = xmlImporter.ImportAnyType(parts[0].Type, parts[0].Name); xmlMembers.Add(membersMapping); return membersMapping; } XmlQualifiedName[] names = new XmlQualifiedName[parts.Length]; for (int i = 0; i < parts.Length; i++) names[i] = parts[i].Element; membersMapping = xmlImporter.ImportMembersMapping(names); } xmlMembers.Add(membersMapping); return membersMapping; }
XmlMembersMapping ImportMembersMapping (Message msg, SoapBodyBinding sbb, SoapBindingStyle style, bool output) { string elemName = Operation.Name; if (output) elemName += "Response"; if (msg.Parts.Count == 1 && msg.Parts[0].Name == "parameters") { // Wrapped parameter style MessagePart part = msg.Parts[0]; if (sbb.Use == SoapBindingUse.Encoded) { SoapSchemaMember ssm = new SoapSchemaMember (); ssm.MemberName = part.Name; ssm.MemberType = part.Type; return soapImporter.ImportMembersMapping (elemName, part.Type.Namespace, ssm); } else return xmlImporter.ImportMembersMapping (part.Element); } else { if (sbb.Use == SoapBindingUse.Encoded) { SoapSchemaMember[] mems = new SoapSchemaMember [msg.Parts.Count]; for (int n=0; n<mems.Length; n++) { SoapSchemaMember mem = new SoapSchemaMember(); mem.MemberName = msg.Parts[n].Name; mem.MemberType = msg.Parts[n].Type; mems[n] = mem; } // Rpc messages always have a wrapping element if (style == SoapBindingStyle.Rpc) return soapImporter.ImportMembersMapping (elemName, sbb.Namespace, mems, true); else return soapImporter.ImportMembersMapping ("", "", mems, false); } else { if (style == SoapBindingStyle.Rpc) throw new InvalidOperationException ("The combination of style=rpc with use=literal is not supported"); if (msg.Parts.Count == 1 && msg.Parts[0].Type != XmlQualifiedName.Empty) return xmlImporter.ImportAnyType (msg.Parts[0].Type, null); else { XmlQualifiedName[] pnames = new XmlQualifiedName [msg.Parts.Count]; for (int n=0; n<pnames.Length; n++) pnames[n] = msg.Parts[n].Element; return xmlImporter.ImportMembersMapping (pnames); } } } }
internal static bool AnalyzeBinding(Binding binding, ServiceDescription description, ServiceDescriptionCollection descriptions, BasicProfileViolationCollection violations) { bool flag = false; bool flag2 = false; SoapBinding binding2 = (SoapBinding)binding.Extensions.Find(typeof(SoapBinding)); if ((binding2 == null) || (binding2.GetType() != typeof(SoapBinding))) { return(false); } SoapBindingStyle style = (binding2.Style == SoapBindingStyle.Default) ? SoapBindingStyle.Document : binding2.Style; if (binding2.Transport.Length == 0) { violations.Add("R2701", System.Web.Services.Res.GetString("BindingMissingAttribute", new object[] { binding.Name, description.TargetNamespace, "transport" })); } else if (binding2.Transport != "http://schemas.xmlsoap.org/soap/http") { violations.Add("R2702", System.Web.Services.Res.GetString("BindingInvalidAttribute", new object[] { binding.Name, description.TargetNamespace, "transport", binding2.Transport })); } PortType portType = descriptions.GetPortType(binding.Type); Hashtable hashtable = new Hashtable(); if (portType != null) { foreach (Operation operation in portType.Operations) { if (operation.Messages.Flow == OperationFlow.Notification) { violations.Add("R2303", System.Web.Services.Res.GetString("OperationFlowNotification", new object[] { operation.Name, binding.Type.Namespace, binding.Type.Namespace })); } if (operation.Messages.Flow == OperationFlow.SolicitResponse) { violations.Add("R2303", System.Web.Services.Res.GetString("OperationFlowSolicitResponse", new object[] { operation.Name, binding.Type.Namespace, binding.Type.Namespace })); } if (hashtable[operation.Name] != null) { violations.Add("R2304", System.Web.Services.Res.GetString("Operation", new object[] { operation.Name, binding.Type.Name, binding.Type.Namespace })); } else { OperationBinding binding3 = null; foreach (OperationBinding binding4 in binding.Operations) { if (operation.IsBoundBy(binding4)) { if (binding3 != null) { violations.Add("R2304", System.Web.Services.Res.GetString("OperationBinding", new object[] { binding3.Name, binding3.Parent.Name, description.TargetNamespace })); } binding3 = binding4; } } if (binding3 == null) { violations.Add("R2718", System.Web.Services.Res.GetString("OperationMissingBinding", new object[] { operation.Name, binding.Type.Name, binding.Type.Namespace })); } else { hashtable.Add(operation.Name, operation); } } } } Hashtable wireSignatures = new Hashtable(); SoapBindingStyle style2 = SoapBindingStyle.Default; foreach (OperationBinding binding5 in binding.Operations) { SoapBindingStyle style3 = style; string name = binding5.Name; if (name != null) { if (hashtable[name] == null) { violations.Add("R2718", System.Web.Services.Res.GetString("PortTypeOperationMissing", new object[] { binding5.Name, binding.Name, description.TargetNamespace, binding.Type.Name, binding.Type.Namespace })); } Operation operation2 = FindOperation(portType.Operations, binding5); SoapOperationBinding binding6 = (SoapOperationBinding)binding5.Extensions.Find(typeof(SoapOperationBinding)); if (binding6 != null) { if (style2 == SoapBindingStyle.Default) { style2 = binding6.Style; } flag |= style2 != binding6.Style; style3 = (binding6.Style != SoapBindingStyle.Default) ? binding6.Style : style; } if (binding5.Input != null) { SoapBodyBinding binding7 = FindSoapBodyBinding(true, binding5.Input.Extensions, violations, style3 == SoapBindingStyle.Document, binding5.Name, binding.Name, description.TargetNamespace); if ((binding7 != null) && (binding7.Use != SoapBindingUse.Encoded)) { Message message = (operation2 == null) ? null : ((operation2.Messages.Input == null) ? null : descriptions.GetMessage(operation2.Messages.Input.Message)); if (style3 == SoapBindingStyle.Rpc) { CheckMessageParts(message, binding7.Parts, false, binding5.Name, binding.Name, description.TargetNamespace, wireSignatures, violations); } else { flag2 = flag2 || ((binding7.Parts != null) && (binding7.Parts.Length > 1)); int num = (binding7.Parts == null) ? 0 : binding7.Parts.Length; CheckMessageParts(message, binding7.Parts, true, binding5.Name, binding.Name, description.TargetNamespace, wireSignatures, violations); if (((num == 0) && (message != null)) && (message.Parts.Count > 1)) { violations.Add("R2210", System.Web.Services.Res.GetString("OperationBinding", new object[] { binding5.Name, binding.Name, description.TargetNamespace })); } } } } if (binding5.Output != null) { SoapBodyBinding binding8 = FindSoapBodyBinding(false, binding5.Output.Extensions, violations, style3 == SoapBindingStyle.Document, binding5.Name, binding.Name, description.TargetNamespace); if ((binding8 != null) && (binding8.Use != SoapBindingUse.Encoded)) { Message message2 = (operation2 == null) ? null : ((operation2.Messages.Output == null) ? null : descriptions.GetMessage(operation2.Messages.Output.Message)); if (style3 == SoapBindingStyle.Rpc) { CheckMessageParts(message2, binding8.Parts, false, binding5.Name, binding.Name, description.TargetNamespace, null, violations); } else { flag2 = flag2 || ((binding8.Parts != null) && (binding8.Parts.Length > 1)); int num2 = (binding8.Parts == null) ? 0 : binding8.Parts.Length; CheckMessageParts(message2, binding8.Parts, true, binding5.Name, binding.Name, description.TargetNamespace, null, violations); if (((num2 == 0) && (message2 != null)) && (message2.Parts.Count > 1)) { violations.Add("R2210", System.Web.Services.Res.GetString("OperationBinding", new object[] { binding5.Name, binding.Name, description.TargetNamespace })); } } } } foreach (FaultBinding binding9 in binding5.Faults) { foreach (ServiceDescriptionFormatExtension extension in binding9.Extensions) { if (extension is SoapFaultBinding) { SoapFaultBinding item = (SoapFaultBinding)extension; if (item.Use == SoapBindingUse.Encoded) { violations.Add("R2706", MessageString(item, binding5.Name, binding.Name, description.TargetNamespace, false, null)); } else { if ((item.Name == null) || (item.Name.Length == 0)) { violations.Add("R2721", System.Web.Services.Res.GetString("FaultBinding", new object[] { binding9.Name, binding5.Name, binding.Name, description.TargetNamespace })); } else if (item.Name != binding9.Name) { violations.Add("R2754", System.Web.Services.Res.GetString("FaultBinding", new object[] { binding9.Name, binding5.Name, binding.Name, description.TargetNamespace })); } if ((item.Namespace != null) && (item.Namespace.Length > 0)) { violations.Add((style3 == SoapBindingStyle.Document) ? "R2716" : "R2726", MessageString(item, binding5.Name, binding.Name, description.TargetNamespace, false, null)); } } } } } if (hashtable[binding5.Name] == null) { violations.Add("R2718", System.Web.Services.Res.GetString("PortTypeOperationMissing", new object[] { binding5.Name, binding.Name, description.TargetNamespace, binding.Type.Name, binding.Type.Namespace })); } } } if (flag2) { violations.Add("R2201", System.Web.Services.Res.GetString("BindingMultipleParts", new object[] { binding.Name, description.TargetNamespace, "parts" })); } if (flag) { violations.Add("R2705", System.Web.Services.Res.GetString("Binding", new object[] { binding.Name, description.TargetNamespace })); } return(true); }
void CreateInputBinding (ServiceEndpoint endpoint, OperationBinding op_binding, MessageDescription sm_md) { var in_binding = new InputBinding (); op_binding.Input = in_binding; var message_version = endpoint.Binding.MessageVersion ?? MessageVersion.None; if (message_version == MessageVersion.None) return; SoapBodyBinding soap_body_binding; SoapOperationBinding soap_operation_binding; if (message_version.Envelope == EnvelopeVersion.Soap11) { soap_body_binding = new SoapBodyBinding (); soap_operation_binding = new SoapOperationBinding (); } else if (message_version.Envelope == EnvelopeVersion.Soap12) { soap_body_binding = new Soap12BodyBinding (); soap_operation_binding = new Soap12OperationBinding (); } else { throw new InvalidOperationException (); } soap_body_binding.Use = SoapBindingUse.Literal; in_binding.Extensions.Add (soap_body_binding); //Set Action //<operation > <soap:operation soapAction .. > soap_operation_binding.SoapAction = sm_md.Action; soap_operation_binding.Style = SoapBindingStyle.Document; op_binding.Extensions.Add (soap_operation_binding); }
XmlMembersMapping ImportMembersMapping(Message msg, SoapBodyBinding sbb, SoapBindingStyle style, bool output, bool wrapped) { string elemName = Operation.Name; if (output) { elemName += "Response"; } if (wrapped) { // Wrapped parameter style MessagePart part = msg.Parts[0]; if (sbb.Use == SoapBindingUse.Encoded) { SoapSchemaMember ssm = new SoapSchemaMember(); ssm.MemberName = part.Name; ssm.MemberType = part.Type; return(soapImporter.ImportMembersMapping(elemName, part.Type.Namespace, ssm)); } else { return(xmlImporter.ImportMembersMapping(part.Element)); } } else { if (sbb.Use == SoapBindingUse.Encoded) { SoapSchemaMember[] mems = new SoapSchemaMember [msg.Parts.Count]; for (int n = 0; n < mems.Length; n++) { SoapSchemaMember mem = new SoapSchemaMember(); mem.MemberName = msg.Parts[n].Name; mem.MemberType = msg.Parts[n].Type; mems[n] = mem; } // Rpc messages always have a wrapping element if (style == SoapBindingStyle.Rpc) { return(soapImporter.ImportMembersMapping(elemName, sbb.Namespace, mems, true)); } else { return(soapImporter.ImportMembersMapping("", "", mems, false)); } } else { if (style == SoapBindingStyle.Rpc) { throw new InvalidOperationException("The combination of style=rpc with use=literal is not supported"); } if (msg.Parts.Count == 1 && msg.Parts[0].Type != XmlQualifiedName.Empty) { return(xmlImporter.ImportAnyType(msg.Parts[0].Type, null)); } else { XmlQualifiedName[] pnames = new XmlQualifiedName [msg.Parts.Count]; for (int n = 0; n < pnames.Length; n++) { pnames[n] = msg.Parts[n].Element; } return(xmlImporter.ImportMembersMapping(pnames)); } } } }
protected virtual SoapBodyBinding CreateSoapBodyBinding(SoapBindingUse use, string ns) { SoapBodyBinding soapBodyBinding = new SoapBodyBinding(); soapBodyBinding.Use = use; if (use == SoapBindingUse.Encoded) soapBodyBinding.Encoding = Soap.Encoding; soapBodyBinding.Namespace = ns; return soapBodyBinding; }
XmlMembersMapping ImportEncodedMessage(string messageName, MessagePart[] parts, SoapBodyBinding soapBodyBinding, bool wrapped) { XmlMembersMapping membersMapping; if (wrapped) { SoapSchemaMember schemaMember = new SoapSchemaMember(); schemaMember.MemberName = parts[0].Name; schemaMember.MemberType = parts[0].Type; membersMapping = soapImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, schemaMember); } else { SoapSchemaMember[] schemaMembers = new SoapSchemaMember[parts.Length]; for (int i = 0; i < schemaMembers.Length; i++) { MessagePart part = parts[i]; SoapSchemaMember schemaMember = new SoapSchemaMember(); schemaMember.MemberName = part.Name; schemaMember.MemberType = part.Type; schemaMembers[i] = schemaMember; } membersMapping = soapImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, schemaMembers); } soapMembers.Add(membersMapping); return membersMapping; }
public override void ExportEndpoint (ServiceEndpoint endpoint) { List<IWsdlExportExtension> extensions = ExportContractInternal (endpoint.Contract); //FIXME: Namespace WSServiceDescription sd = GetServiceDescription ("http://tempuri.org/"); if (sd.TargetNamespace != endpoint.Contract.Namespace) { sd.Namespaces.Add ("i0", endpoint.Contract.Namespace); //Import Import import = new Import (); import.Namespace = endpoint.Contract.Namespace; sd.Imports.Add (import); } if (endpoint.Binding == null) throw new ArgumentException (String.Format ( "Binding for ServiceEndpoint named '{0}' is null", endpoint.Name)); bool msg_version_none = endpoint.Binding.MessageVersion != null && endpoint.Binding.MessageVersion.Equals (MessageVersion.None); //ExportBinding WSBinding ws_binding = new WSBinding (); //<binding name = .. ws_binding.Name = String.Concat (endpoint.Binding.Name, "_", endpoint.Contract.Name); //<binding type = .. ws_binding.Type = new QName (endpoint.Contract.Name, endpoint.Contract.Namespace); sd.Bindings.Add (ws_binding); if (!msg_version_none) { SoapBinding soap_binding = new SoapBinding (); soap_binding.Transport = SoapBinding.HttpTransport; soap_binding.Style = SoapBindingStyle.Document; ws_binding.Extensions.Add (soap_binding); } // <operation foreach (OperationDescription sm_op in endpoint.Contract.Operations){ OperationBinding op_binding = new OperationBinding (); op_binding.Name = sm_op.Name; //FIXME: Move to IWsdlExportExtension .. ? foreach (MessageDescription sm_md in sm_op.Messages) { if (sm_md.Direction == MessageDirection.Input) { //<input InputBinding in_binding = new InputBinding (); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding (); soap_body_binding.Use = SoapBindingUse.Literal; in_binding.Extensions.Add (soap_body_binding); //Set Action //<operation > <soap:operation soapAction .. > SoapOperationBinding soap_operation_binding = new SoapOperationBinding (); soap_operation_binding.SoapAction = sm_md.Action; soap_operation_binding.Style = SoapBindingStyle.Document; op_binding.Extensions.Add (soap_operation_binding); } op_binding.Input = in_binding; } else { //<output OutputBinding out_binding = new OutputBinding (); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding (); soap_body_binding.Use = SoapBindingUse.Literal; out_binding.Extensions.Add (soap_body_binding); } op_binding.Output = out_binding; } } ws_binding.Operations.Add (op_binding); } //Add <service Port ws_port = ExportService (sd, ws_binding, endpoint.Address, msg_version_none); //Call IWsdlExportExtension.ExportEndpoint WsdlContractConversionContext contract_context = new WsdlContractConversionContext ( endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext ( contract_context, endpoint, ws_port, ws_binding); foreach (IWsdlExportExtension extn in extensions) extn.ExportEndpoint (this, endpoint_context); }
/// <summary> /// Search and returns the type mapping between method parameters/return value /// and the element parts of a literal-use SOAP message. /// </summary> private XmlMembersMapping GetMembersMapping(string messageName, MessagePartCollection messageParts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle) { if (soapBindingStyle == SoapBindingStyle.Rpc) { SoapSchemaMember[] soapSchemaMembers = new SoapSchemaMember[messageParts.Count]; for (int i = 0; i < messageParts.Count; i++) { SoapSchemaMember ssm = new SoapSchemaMember(); ssm.MemberName = messageParts[i].Name; ssm.MemberType = messageParts[i].Type; soapSchemaMembers[i] = ssm; } return this.schemaImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, soapSchemaMembers); } else { return this.schemaImporter.ImportMembersMapping(messageParts[0].Element); } }
protected override CodeMemberMethod GenerateMethod() { try { SoapOperationBinding soapOper = OperationBinding.Extensions.Find(typeof(SoapOperationBinding)) as SoapOperationBinding; if (soapOper == null) { throw new InvalidOperationException("Soap operation binding not found"); } SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style; SoapBodyBinding isbb = null; XmlMembersMapping inputMembers = null; bool isWrapped = CheckIsWrapped(); isbb = OperationBinding.Input.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding; if (isbb == null) { throw new InvalidOperationException("Soap body binding not found"); } inputMembers = ImportMembersMapping(InputMessage, isbb, style, false, isWrapped); if (inputMembers == null) { throw new InvalidOperationException("Input message not declared"); } // If OperationBinding.Output is null, it is an OneWay operation SoapBodyBinding osbb = null; XmlMembersMapping outputMembers = null; if (OperationBinding.Output != null) { osbb = OperationBinding.Output.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding; if (osbb == null) { throw new InvalidOperationException("Soap body binding not found"); } outputMembers = ImportMembersMapping(OutputMessage, osbb, style, true, isWrapped); if (outputMembers == null) { throw new InvalidOperationException("Output message not declared"); } } CodeMemberMethod met = GenerateMethod(memberIds, soapOper, isbb, inputMembers, outputMembers); if (isbb.Use == SoapBindingUse.Literal) { xmlExporter.ExportMembersMapping(inputMembers); } else { soapExporter.ExportMembersMapping(inputMembers); } if (osbb != null) { if (osbb.Use == SoapBindingUse.Literal) { xmlExporter.ExportMembersMapping(outputMembers); } else { soapExporter.ExportMembersMapping(outputMembers); } } foreach (SoapExtensionImporter eximporter in extensionImporters) { eximporter.ImportContext = this; eximporter.ImportMethod(met.CustomAttributes); } return(met); } catch (InvalidOperationException ex) { UnsupportedOperationBindingWarning(ex.Message); return(null); } }
void CheckSoapBindingExtensions(ConformanceCheckContext ctx, Binding value, LiteralType type) { bool violationNS = false; bool violation2717 = false; bool violation2720 = false; bool violation2721 = false; foreach (OperationBinding op in value.Operations) { SoapBodyBinding sbb = op.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding; if (sbb != null) { if (type == LiteralType.Document && sbb.Namespace != null) { violationNS = true; } if (type == LiteralType.Rpc && sbb.Namespace == null) { violation2717 = true; } } SoapHeaderBinding shb = op.Extensions.Find(typeof(SoapHeaderBinding)) as SoapHeaderBinding; if (shb != null) { violationNS |= shb.Namespace != null; violation2720 |= !IsValidPart(shb.Part); } SoapHeaderFaultBinding sfhb = op.Extensions.Find(typeof(SoapHeaderFaultBinding)) as SoapHeaderFaultBinding; if (sfhb != null) { violationNS |= sfhb.Namespace != null; violation2720 |= !IsValidPart(sfhb.Part); } SoapFaultBinding sfb = op.Extensions.Find(typeof(SoapFaultBinding)) as SoapFaultBinding; if (sfb != null) { violation2721 |= sfb.Name == null; violationNS |= sfb.Namespace != null; } } if (violationNS) { ctx.ReportRuleViolation(value, type == LiteralType.Document ? BasicProfileRules.R2716 : BasicProfileRules.R2726); } if (violation2717) { ctx.ReportRuleViolation(value, BasicProfileRules.R2717); } if (violation2720) { ctx.ReportRuleViolation(value, BasicProfileRules.R2720); } if (violation2721) { ctx.ReportRuleViolation(value, BasicProfileRules.R2721); } }
CodeMemberMethod GenerateMethod(CodeIdentifiers memberIds, SoapOperationBinding soapOper, SoapBodyBinding bodyBinding, XmlMembersMapping inputMembers, XmlMembersMapping outputMembers) { CodeIdentifiers pids = new CodeIdentifiers(); CodeMemberMethod method = new CodeMemberMethod(); CodeMemberMethod methodBegin = new CodeMemberMethod(); CodeMemberMethod methodEnd = new CodeMemberMethod(); method.Attributes = MemberAttributes.Public | MemberAttributes.Final; methodBegin.Attributes = MemberAttributes.Public | MemberAttributes.Final; methodEnd.Attributes = MemberAttributes.Public | MemberAttributes.Final; SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style; // Find unique names for temporary variables for (int n = 0; n < inputMembers.Count; n++) { pids.AddUnique(inputMembers[n].MemberName, inputMembers[n]); } if (outputMembers != null) { for (int n = 0; n < outputMembers.Count; n++) { pids.AddUnique(outputMembers[n].MemberName, outputMembers[n]); } } string varAsyncResult = pids.AddUnique("asyncResult", "asyncResult"); string varResults = pids.AddUnique("results", "results"); string varCallback = pids.AddUnique("callback", "callback"); string varAsyncState = pids.AddUnique("asyncState", "asyncState"); string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name), method); method.Name = CodeIdentifier.MakeValid(Operation.Name); if (method.Name == ClassName) { method.Name += "1"; } methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + method.Name), method); methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + method.Name), method); method.ReturnType = new CodeTypeReference(typeof(void)); methodEnd.ReturnType = new CodeTypeReference(typeof(void)); methodEnd.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IAsyncResult), varAsyncResult)); CodeExpression[] paramArray = new CodeExpression [inputMembers.Count]; CodeParameterDeclarationExpression[] outParams = new CodeParameterDeclarationExpression [outputMembers != null ? outputMembers.Count : 0]; for (int n = 0; n < inputMembers.Count; n++) { CodeParameterDeclarationExpression param = GenerateParameter(inputMembers[n], FieldDirection.In); method.Parameters.Add(param); GenerateMemberAttributes(inputMembers, inputMembers[n], bodyBinding.Use, param); methodBegin.Parameters.Add(GenerateParameter(inputMembers[n], FieldDirection.In)); paramArray [n] = new CodeVariableReferenceExpression(param.Name); } if (outputMembers != null) { bool hasReturn = false; for (int n = 0; n < outputMembers.Count; n++) { CodeParameterDeclarationExpression cpd = GenerateParameter(outputMembers[n], FieldDirection.Out); outParams [n] = cpd; bool found = false; foreach (CodeParameterDeclarationExpression ip in method.Parameters) { if (ip.Name == cpd.Name && ip.Type.BaseType == cpd.Type.BaseType) { ip.Direction = FieldDirection.Ref; methodEnd.Parameters.Add(GenerateParameter(outputMembers[n], FieldDirection.Out)); found = true; break; } } if (found) { continue; } if (!hasReturn) { hasReturn = true; method.ReturnType = cpd.Type; methodEnd.ReturnType = cpd.Type; GenerateReturnAttributes(outputMembers, outputMembers[n], bodyBinding.Use, method); outParams [n] = null; continue; } method.Parameters.Add(cpd); GenerateMemberAttributes(outputMembers, outputMembers[n], bodyBinding.Use, cpd); methodEnd.Parameters.Add(GenerateParameter(outputMembers[n], FieldDirection.Out)); } } methodBegin.Parameters.Add(new CodeParameterDeclarationExpression(typeof(AsyncCallback), varCallback)); methodBegin.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), varAsyncState)); methodBegin.ReturnType = new CodeTypeReference(typeof(IAsyncResult)); // Array of input parameters CodeArrayCreateExpression methodParams; if (paramArray.Length > 0) { methodParams = new CodeArrayCreateExpression(typeof(object), paramArray); } else { methodParams = new CodeArrayCreateExpression(typeof(object), 0); } // Assignment of output parameters CodeStatementCollection outAssign = new CodeStatementCollection(); CodeVariableReferenceExpression arrVar = new CodeVariableReferenceExpression(varResults); for (int n = 0; n < outParams.Length; n++) { CodeExpression index = new CodePrimitiveExpression(n); if (outParams[n] == null) { CodeExpression res = new CodeCastExpression(method.ReturnType, new CodeArrayIndexerExpression(arrVar, index)); outAssign.Add(new CodeMethodReturnStatement(res)); } else { CodeExpression res = new CodeCastExpression(outParams[n].Type, new CodeArrayIndexerExpression(arrVar, index)); CodeExpression var = new CodeVariableReferenceExpression(outParams[n].Name); outAssign.Insert(0, new CodeAssignStatement(var, res)); } } if (Style == ServiceDescriptionImportStyle.Client) { // Invoke call CodeThisReferenceExpression ethis = new CodeThisReferenceExpression(); CodePrimitiveExpression varMsgName = new CodePrimitiveExpression(messageName); CodeMethodInvokeExpression inv; CodeVariableDeclarationStatement dec; inv = new CodeMethodInvokeExpression(ethis, "Invoke", varMsgName, methodParams); if (outputMembers != null && outputMembers.Count > 0) { dec = new CodeVariableDeclarationStatement(typeof(object[]), varResults, inv); method.Statements.Add(dec); method.Statements.AddRange(outAssign); } else { method.Statements.Add(inv); } // Begin Invoke Call CodeExpression expCallb = new CodeVariableReferenceExpression(varCallback); CodeExpression expAsyncs = new CodeVariableReferenceExpression(varAsyncState); inv = new CodeMethodInvokeExpression(ethis, "BeginInvoke", varMsgName, methodParams, expCallb, expAsyncs); methodBegin.Statements.Add(new CodeMethodReturnStatement(inv)); // End Invoke call CodeExpression varAsyncr = new CodeVariableReferenceExpression(varAsyncResult); inv = new CodeMethodInvokeExpression(ethis, "EndInvoke", varAsyncr); if (outputMembers != null && outputMembers.Count > 0) { dec = new CodeVariableDeclarationStatement(typeof(object[]), varResults, inv); methodEnd.Statements.Add(dec); methodEnd.Statements.AddRange(outAssign); } else { methodEnd.Statements.Add(inv); } } else { method.Attributes = MemberAttributes.Public | MemberAttributes.Abstract; } // Attributes ImportHeaders(method); CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Web.Services.WebMethodAttribute"); if (messageName != method.Name) { att.Arguments.Add(GetArg("MessageName", messageName)); } AddCustomAttribute(method, att, (Style == ServiceDescriptionImportStyle.Server)); if (style == SoapBindingStyle.Rpc) { att = new CodeAttributeDeclaration("System.Web.Services.Protocols.SoapRpcMethodAttribute"); att.Arguments.Add(GetArg(soapOper.SoapAction)); if (inputMembers.ElementName != method.Name) { att.Arguments.Add(GetArg("RequestElementName", inputMembers.ElementName)); } if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) { att.Arguments.Add(GetArg("ResponseElementName", outputMembers.ElementName)); } att.Arguments.Add(GetArg("RequestNamespace", inputMembers.Namespace)); if (outputMembers != null) { att.Arguments.Add(GetArg("ResponseNamespace", outputMembers.Namespace)); } if (outputMembers == null) { att.Arguments.Add(GetArg("OneWay", true)); } } else { if (outputMembers != null && (inputMembers.ElementName == "" && outputMembers.ElementName != "" || inputMembers.ElementName != "" && outputMembers.ElementName == "")) { throw new InvalidOperationException("Parameter style is not the same for the input message and output message"); } att = new CodeAttributeDeclaration("System.Web.Services.Protocols.SoapDocumentMethodAttribute"); att.Arguments.Add(GetArg(soapOper.SoapAction)); if (inputMembers.ElementName != "") { if (inputMembers.ElementName != method.Name) { att.Arguments.Add(GetArg("RequestElementName", inputMembers.ElementName)); } if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) { att.Arguments.Add(GetArg("ResponseElementName", outputMembers.ElementName)); } att.Arguments.Add(GetArg("RequestNamespace", inputMembers.Namespace)); if (outputMembers != null) { att.Arguments.Add(GetArg("ResponseNamespace", outputMembers.Namespace)); } att.Arguments.Add(GetEnumArg("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Wrapped")); } else { att.Arguments.Add(GetEnumArg("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Bare")); } if (outputMembers == null) { att.Arguments.Add(GetArg("OneWay", true)); } att.Arguments.Add(GetEnumArg("Use", "System.Web.Services.Description.SoapBindingUse", bodyBinding.Use.ToString())); } AddCustomAttribute(method, att, true); CodeTypeDeclaration.Members.Add(method); if (Style == ServiceDescriptionImportStyle.Client) { CodeTypeDeclaration.Members.Add(methodBegin); CodeTypeDeclaration.Members.Add(methodEnd); } return(method); }
void AddOperationMsgBindings (SoapMethodStubInfo method, MessageBinding msg) { SoapBodyBinding sbbo = new SoapBodyBinding(); msg.Extensions.Add (sbbo); sbbo.Use = method.Use; if (method.Use == SoapBindingUse.Encoded) { sbbo.Namespace = ServiceDescription.TargetNamespace; sbbo.Encoding = EncodingNamespace; } }