Exemplo n.º 1
0
        private static WsdlNS.SoapBinding GetSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExporter exporter)
        {
            EnvelopeVersion envelopeVersion = null;

            WsdlNS.SoapBinding existingSoapBinding = null;
            object             versions            = null;
            object             SoapVersionStateKey = new object();

            //get the soap version state
            if (exporter.State.TryGetValue(SoapVersionStateKey, out versions))
            {
                if (versions != null && ((Dictionary <WsdlNS.Binding, EnvelopeVersion>)versions).ContainsKey(endpointContext.WsdlBinding))
                {
                    envelopeVersion = ((Dictionary <WsdlNS.Binding, EnvelopeVersion>)versions)[endpointContext.WsdlBinding];
                }
            }

            if (envelopeVersion == EnvelopeVersion.None)
            {
                return(null);
            }

            //get existing soap binding
            foreach (object o in endpointContext.WsdlBinding.Extensions)
            {
                if (o is WsdlNS.SoapBinding)
                {
                    existingSoapBinding = (WsdlNS.SoapBinding)o;
                }
            }

            return(existingSoapBinding);
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

#pragma warning suppress 56506 // Microsoft, these properties cannot be null in this context
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

#pragma warning suppress 56506 // Microsoft, CustomBinding.Elements never be null
            TransportBindingElement transportBindingElement = GetBindingElements(context).Find <TransportBindingElement>();

            bool transportHandledExternaly = (transportBindingElement != null) && !StateHelper.IsRegisteredTransportBindingElement(importer, context);
            if (transportHandledExternaly)
            {
                return;
            }

#pragma warning suppress 56506 // Microsoft, these properties cannot be null in this context
            WsdlNS.SoapBinding soapBinding = (WsdlNS.SoapBinding)context.WsdlBinding.Extensions.Find(typeof(WsdlNS.SoapBinding));
            if (soapBinding != null && transportBindingElement == null)
            {
                CreateLegacyTransportBindingElement(importer, soapBinding, context);
            }

            // Try to import WS-Addressing address from the port
            if (context.WsdlPort != null)
            {
                ImportAddress(context, transportBindingElement);
            }
        }
        public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            BindingElementCollection      bindingElements        = context.Endpoint.Binding.CreateBindingElements();
            MessageEncodingBindingElement encodingBindingElement = bindingElements.Find <MessageEncodingBindingElement>();

            if (encodingBindingElement == null)
            {
                encodingBindingElement = new TextMessageEncodingBindingElement();
            }

            // Set SoapBinding Transport URI
            if (UdpPolicyStrings.UdpNamespace != null)
            {
                WsdlNS.SoapBinding soapBinding = GetSoapBinding(context, exporter);

                if (soapBinding != null)
                {
                    soapBinding.Transport = UdpPolicyStrings.UdpNamespace;
                }
            }

            if (context.WsdlPort != null)
            {
                AddAddressToWsdlPort(context.WsdlPort, context.Endpoint.Address, encodingBindingElement.MessageVersion.Addressing);
            }
        }
Exemplo n.º 4
0
        internal static WS.SoapBinding GetHttpSoapBinding(WS.Binding binding)
        {
            WS.SoapBinding soap = null;
            foreach (var extension in binding.Extensions)
            {
                var check = extension as WS.SoapBinding;
                if (check != null)
                {
                    soap = check;
                    break;
                }
            }

            if (soap == null)
            {
                return(null);
            }
            if (soap.Transport != WS.SoapBinding.HttpTransport)
            {
                return(null);
            }
            if (soap.Style != WS.SoapBindingStyle.Document)
            {
                return(null);
            }
            return(soap);
        }
        internal static void ExportWsdlEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext,
                                                string wsdlTransportUri, EndpointAddress address, AddressingVersion addressingVersion)
        {
            if (exporter == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            if (endpointContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext");
            }

            // Set SoapBinding Transport URI
#pragma warning suppress 56506 // [....], these properties cannot be null in this context
            BindingElementCollection bindingElements = endpointContext.Endpoint.Binding.CreateBindingElements();
            if (wsdlTransportUri != null)
            {
                WsdlNS.SoapBinding soapBinding = SoapHelper.GetOrCreateSoapBinding(endpointContext, exporter);

                if (soapBinding != null)
                {
                    soapBinding.Transport = wsdlTransportUri;
                }
            }

            if (endpointContext.WsdlPort != null)
            {
                WsdlExporter.WSAddressingHelper.AddAddressToWsdlPort(endpointContext.WsdlPort, address, addressingVersion);
            }
        }
Exemplo n.º 6
0
        bool ImportHttpPolicy(MetadataImporter importer, PolicyConversionContext context,
                              WS.SoapBinding soap)
        {
            HttpTransportBindingElement httpTransport;
            var assertions      = context.GetBindingAssertions();
            var transportPolicy = PolicyImportHelper.GetTransportBindingPolicy(assertions);

            if (transportPolicy != null)
            {
                if (!ImportHttpTransport(importer, context, transportPolicy, out httpTransport))
                {
                    return(false);
                }
                if (!ImportTransport(importer, httpTransport, transportPolicy))
                {
                    return(false);
                }
            }
            else
            {
                httpTransport = new HttpTransportBindingElement();
            }

            if (!ImportHttpAuthScheme(importer, httpTransport, context))
            {
                return(false);
            }

            context.BindingElements.Add(httpTransport);
            return(true);
        }
            internal static bool ConvertSoapBinding(ref object src, EnvelopeVersion version)
            {
                WsdlNS.SoapBinding binding = src as WsdlNS.SoapBinding;

                if (src != null)
                {
                    if (binding == null)
                    {
                        return(false); // not a soap object
                    }
                    else if (GetBindingVersion <WsdlNS.Soap12Binding>(src) == version)
                    {
                        return(true); // matched but same version; no change
                    }
                }

                if (version == EnvelopeVersion.None)
                {
                    src = null;
                    return(true);
                }

                WsdlNS.SoapBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12Binding() : new WsdlNS.SoapBinding();
                if (binding != null)
                {
                    dest.Required  = binding.Required;
                    dest.Style     = binding.Style;
                    dest.Transport = binding.Transport;
                }

                src = dest;
                return(true);
            }
Exemplo n.º 8
0
        protected virtual SoapBinding CreateSoapBinding(SoapBindingStyle style)
        {
            SoapBinding soapBinding = new SoapBinding();

            soapBinding.Transport = SoapBinding.HttpTransport;
            soapBinding.Style     = style;
            return(soapBinding);
        }
Exemplo n.º 9
0
        private static void CheckExtensions(Binding binding, ServiceDescription description, BasicProfileViolationCollection violations)
        {
            SoapBinding binding2 = (SoapBinding)binding.Extensions.Find(typeof(SoapBinding));

            if (((binding2 != null) && (binding2.GetType() == typeof(SoapBinding))) && !CheckExtensions(binding.Extensions))
            {
                violations.Add("R2026", System.Web.Services.Res.GetString("BindingInvalidAttribute", new object[] { binding.Name, description.TargetNamespace, "wsdl:required", "true" }));
            }
        }
 private static void CreateLegacyTransportBindingElement(WsdlImporter importer, SoapBinding soapBinding, WsdlEndpointConversionContext context)
 {
     TransportBindingElement item = CreateTransportBindingElements(soapBinding.Transport, null);
     if (item != null)
     {
         ConvertToCustomBinding(context).Elements.Add(item);
         StateHelper.RegisterTransportBindingElement(importer, context);
     }
 }
        static void CreateLegacyTransportBindingElement(WsdlImporter importer, WsdlNS.SoapBinding soapBinding, WsdlEndpointConversionContext context)
        {
            // We create a transportBindingElement based on the SoapBinding's Transport
            TransportBindingElement transportBindingElement = CreateTransportBindingElements(soapBinding.Transport, null);

            if (transportBindingElement != null)
            {
                ConvertToCustomBinding(context).Elements.Add(transportBindingElement);
                StateHelper.RegisterTransportBindingElement(importer, context);
            }
        }
		protected override void BeginClass ()
		{
			SoapBinding sb = new SoapBinding ();
			sb.Transport = SoapBinding.HttpTransport;
			sb.Style = ((SoapTypeStubInfo)TypeInfo).SoapBindingStyle;
			Binding.Extensions.Add (sb);

			SoapAddressBinding abind = new SoapAddressBinding ();
			abind.Location = ServiceUrl;
			Port.Extensions.Add (abind);
		}
 internal static WsdlNS.SoapBindingStyle GetStyle(WsdlNS.Binding binding)
 {
     WsdlNS.SoapBindingStyle style = WsdlNS.SoapBindingStyle.Default;
     if (binding != null)
     {
         WsdlNS.SoapBinding soapBinding = binding.Extensions.Find(typeof(WsdlNS.SoapBinding)) as WsdlNS.SoapBinding;
         if (soapBinding != null)
         {
             style = soapBinding.Style;
         }
     }
     return(style);
 }
        override void ReflectDescription()
        {
            SoapBinding sb = CreateSoapBinding();

            sb.Transport = SoapBinding.HttpTransport;
            sb.Style     = ((SoapTypeStubInfo)ReflectionContext.TypeInfo).SoapBindingStyle;
            ReflectionContext.Binding.Extensions.Add(sb);

            SoapAddressBinding abind = CreateSoapAddressBinding();

            abind.Location = ReflectionContext.ServiceUrl;
            ReflectionContext.Port.Extensions.Add(abind);
        }
        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter,
                                                 WsdlEndpointConversionContext context)
        {
            var soap_binding = new WS.SoapBinding();

            soap_binding.Transport = WS.SoapBinding.HttpTransport;
            soap_binding.Style     = WS.SoapBindingStyle.Document;
            context.WsdlBinding.Extensions.Add(soap_binding);

            var soap_address = new WS.SoapAddressBinding();

            soap_address.Location = context.Endpoint.Address.Uri.AbsoluteUri;

            context.WsdlPort.Extensions.Add(soap_address);
        }
        //
        static WsdlNS.SoapBinding CreateSoapBinding(EnvelopeVersion version, WsdlNS.Binding wsdlBinding)
        {
            WsdlNS.SoapBinding soapBinding = null;

            if (version == EnvelopeVersion.Soap12)
            {
                soapBinding = new WsdlNS.Soap12Binding();
            }
            else if (version == EnvelopeVersion.Soap11)
            {
                soapBinding = new WsdlNS.SoapBinding();
            }
            Fx.Assert(soapBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");

            wsdlBinding.Extensions.Add(soapBinding);
            return(soapBinding);
        }
        internal static WsdlNS.SoapBinding GetOrCreateSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExporter exporter)
        {
            if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None)
            {
                return(null);
            }

            WsdlNS.SoapBinding existingSoapBinding = GetSoapBinding(endpointContext);
            if (existingSoapBinding != null)
            {
                return(existingSoapBinding);
            }

            EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);

            WsdlNS.SoapBinding soapBinding = CreateSoapBinding(version, endpointContext.WsdlBinding);
            return(soapBinding);
        }
Exemplo n.º 18
0
        private static void CheckExtensions(ServiceDescriptionCollection descriptions, BasicProfileViolationCollection violations)
        {
            Hashtable hashtable = new Hashtable();

            foreach (ServiceDescription description in descriptions)
            {
                if ((ServiceDescription.GetConformanceClaims(description.Types.DocumentationElement) == WsiProfiles.BasicProfile1_1) && !CheckExtensions(description.Extensions))
                {
                    violations.Add("R2026", System.Web.Services.Res.GetString("Element", new object[] { "wsdl:types", description.TargetNamespace }));
                }
                foreach (Service service in description.Services)
                {
                    foreach (Port port in service.Ports)
                    {
                        if (ServiceDescription.GetConformanceClaims(port.DocumentationElement) == WsiProfiles.BasicProfile1_1)
                        {
                            if (!CheckExtensions(port.Extensions))
                            {
                                violations.Add("R2026", System.Web.Services.Res.GetString("Port", new object[] { port.Name, service.Name, description.TargetNamespace }));
                            }
                            Binding binding = descriptions.GetBinding(port.Binding);
                            if (hashtable[binding] != null)
                            {
                                CheckExtensions(binding, description, violations);
                                hashtable.Add(binding, binding);
                            }
                        }
                    }
                }
                foreach (Binding binding2 in description.Bindings)
                {
                    SoapBinding binding3 = (SoapBinding)binding2.Extensions.Find(typeof(SoapBinding));
                    if (((binding3 != null) && !(binding3.GetType() != typeof(SoapBinding))) && ((hashtable[binding2] == null) && (ServiceDescription.GetConformanceClaims(binding2.DocumentationElement) == WsiProfiles.BasicProfile1_1)))
                    {
                        CheckExtensions(binding2, description, violations);
                        hashtable.Add(binding2, binding2);
                    }
                }
            }
        }
Exemplo n.º 19
0
        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            BindingElementCollection      bindingElements        = context.Endpoint.Binding.CreateBindingElements();
            MessageEncodingBindingElement encodingBindingElement = bindingElements.Find <MessageEncodingBindingElement>();

            if (encodingBindingElement == null)
            {
                encodingBindingElement = SsbConstants.DefaultMessageEncodingBindingElement;
            }

            // Set SoapBinding Transport URI
            WsdlNS.SoapBinding soapBinding = GetSoapBinding(context, exporter);

            if (soapBinding != null)
            {
                soapBinding.Transport = SsbConstants.SsbNs;
            }
            if (context.WsdlPort != null)
            {
                AddAddressToWsdlPort(context.WsdlPort, context.Endpoint.Address, encodingBindingElement.MessageVersion.Addressing);
            }
        }
Exemplo n.º 20
0
 public void BeforeImport(WsdlNS.ServiceDescriptionCollection wsdlDocuments, Xml.Schema.XmlSchemaSet xmlSchemas, ICollection <Xml.XmlElement> policy)
 {
     foreach (WsdlNS.ServiceDescription wsdl in wsdlDocuments)
     {
         if (wsdl != null)
         {
             foreach (WsdlNS.Binding wsdlBinding in wsdl.Bindings)
             {
                 if (wsdlBinding != null && wsdlBinding.Extensions != null)
                 {
                     WsdlNS.SoapBinding soapBinding = (WsdlNS.SoapBinding)wsdlBinding.Extensions.Find(typeof(WsdlNS.SoapBinding));
                     if (soapBinding != null)
                     {
                         string transportUri = soapBinding.Transport;
                         if (!string.IsNullOrEmpty(transportUri) && transportUri.Equals(UdpConstants.WsdlSoapUdpTransportUri, StringComparison.Ordinal))
                         {
                             WsdlImporter.SoapInPolicyWorkaroundHelper.InsertAdHocPolicy(wsdlBinding, soapBinding.Transport, this.udpTransportUriKey);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 21
0
        public static void BasicHttpBinding(
            TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
            WSMessageEncoding encoding, HttpClientCredentialType clientCred,
            AuthenticationSchemes authScheme, TestLabel label)
        {
            label.EnterScope("basicHttpBinding");

            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");
            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());

            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());

            bool hasPolicyXml;

            switch (security)
            {
            case BasicHttpSecurityMode.None:
                hasPolicyXml = encoding == WSMessageEncoding.Mtom;
                break;

            case BasicHttpSecurityMode.Message:
            case BasicHttpSecurityMode.Transport:
            case BasicHttpSecurityMode.TransportWithMessageCredential:
                if (encoding == WSMessageEncoding.Mtom)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = true;
                break;

            case BasicHttpSecurityMode.TransportCredentialOnly:
                hasPolicyXml = true;
                break;

            default:
                throw new InvalidOperationException();
            }
            label.LeaveScope();

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, WS.SoapBinding.HttpTransport, label);
            label.LeaveScope();

            label.EnterScope("policy-xml");
            if (!hasPolicyXml)
            {
                Assert.That(xml, Is.Null, label.Get());
            }
            else if (context.CheckPolicyXml)
            {
                Assert.That(xml, Is.Not.Null, label.Get());

                Assert.That(xml.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
                Assert.That(xml.LocalName, Is.EqualTo("PolicyReference"), label.Get());
            }
            label.LeaveScope();

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);

            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            string scheme;

            if ((security == BasicHttpSecurityMode.Transport) ||
                (security == BasicHttpSecurityMode.TransportWithMessageCredential))
            {
                scheme = "https";
            }
            else
            {
                scheme = "http";
            }

            CheckBasicHttpBinding(
                bindings [0], scheme, security, encoding, clientCred,
                authScheme, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);

            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            CheckEndpoint(endpoints [0], MetadataSamples.HttpUri, label);
            label.LeaveScope();

            label.LeaveScope();
        }
		void SetBinding (SoapBinding soapBinding)
		{
			this.soapBinding = soapBinding;
		}
 protected virtual SoapBinding CreateSoapBinding(SoapBindingStyle style) {
     SoapBinding soapBinding = new SoapBinding();
     soapBinding.Transport = SoapBinding.HttpTransport;
     soapBinding.Style = style;
     return soapBinding;
 }
 private void Write80_SoapBinding(string n, string ns, SoapBinding o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(SoapBinding)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("SoapBinding", "http://schemas.xmlsoap.org/wsdl/soap/");
         }
         if (o.Required)
         {
             base.WriteAttribute("required", "http://schemas.xmlsoap.org/wsdl/", XmlConvert.ToString(o.Required));
         }
         base.WriteAttribute("transport", "", o.Transport);
         if (o.Style != SoapBindingStyle.Document)
         {
             base.WriteAttribute("style", "", this.Write79_SoapBindingStyle(o.Style));
         }
         base.WriteEndElement(o);
     }
 }
		protected override CodeTypeDeclaration BeginClass ()
		{
			soapBinding = (SoapBinding) Binding.Extensions.Find (typeof(SoapBinding));
			
			CodeTypeDeclaration codeClass = new CodeTypeDeclaration (ClassName);
			
			string location = null;
			
			if (Port != null) {
				SoapAddressBinding sab = (SoapAddressBinding) Port.Extensions.Find (typeof(SoapAddressBinding));
				if (sab != null) location = sab.Location;
			}
			
			string namspace = (Port != null ? Port.Binding.Namespace : Binding.ServiceDescription.TargetNamespace);
			string name = (Port != null ? Port.Name : Binding.Name);

			if (Style == ServiceDescriptionImportStyle.Client) {
				CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.SoapHttpClientProtocol");
				codeClass.BaseTypes.Add (ctr);
			}
			else {
				CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.WebService");
				codeClass.BaseTypes.Add (ctr);
				CodeAttributeDeclaration attws = new CodeAttributeDeclaration ("System.Web.Services.WebServiceAttribute");
				attws.Arguments.Add (GetArg ("Namespace", namspace));
				AddCustomAttribute (codeClass, attws, true);
			}
			
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebServiceBinding");
			att.Arguments.Add (GetArg ("Name", name));
			att.Arguments.Add (GetArg ("Namespace", namspace));
			AddCustomAttribute (codeClass, att, true);
	
			if (Style == ServiceDescriptionImportStyle.Client) {
				CodeConstructor cc = new CodeConstructor ();
				cc.Attributes = MemberAttributes.Public;
				GenerateServiceUrl (location, cc.Statements);
				codeClass.Members.Add (cc);
			}
			
			memberIds = new CodeIdentifiers ();
			headerVariables = new Hashtable ();
			return codeClass;
		}
Exemplo n.º 26
0
		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);

				
		}
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        public void Mtom_Policy()
        {
            var label    = new TestLabel("Mtom_Policy");
            var contract = new ContractDescription("MyContract");
            var binding  = new BasicHttpBinding();

            binding.MessageEncoding = WSMessageEncoding.Mtom;

            var endpoint = new ServiceEndpoint(
                contract, binding, new EndpointAddress(HttpUri));

            var exporter = new WsdlExporter();

            exporter.ExportEndpoint(endpoint);

            Assert.That(exporter.GeneratedWsdlDocuments, Is.Not.Null, label.Get());
            Assert.That(exporter.GeneratedWsdlDocuments.Count, Is.EqualTo(1), label.Get());
            var wsdl = exporter.GeneratedWsdlDocuments [0];

            Assert.That(wsdl.Bindings, Is.Not.Null, label.Get());
            Assert.That(wsdl.Bindings.Count, Is.EqualTo(1), label.Get());

            var wsb = wsdl.Bindings [0];

            label.EnterScope("Binding");
            Assert.That(wsb.Extensions, Is.Not.Null, label.Get());
            Assert.That(wsb.Extensions.Count, Is.EqualTo(2), label.Get());
            label.LeaveScope();

            label.EnterScope("Extensions");
            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var extension in wsb.Extensions)
            {
                if (extension is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)extension;
                }
                else if (extension is XmlElement)
                {
                    xml = (XmlElement)extension;
                }
                else
                {
                    Assert.Fail("Unknown extension.", label);
                }
            }

            Assert.That(soap, Is.Not.Null, label.Get());
            Assert.That(xml, Is.Not.Null, label.Get());
            label.LeaveScope();

            label.EnterScope("Policy");
            var assertions = BindingTestAssertions.AssertPolicy(wsdl, xml, label);

            Assert.That(assertions.Count, Is.EqualTo(1), label.Get());
            var assertion = assertions [0];

            Assert.That(assertion.NamespaceURI, Is.EqualTo("http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"), label.Get());
            Assert.That(assertion.LocalName, Is.EqualTo("OptimizedMimeSerialization"), label.Get());
            label.LeaveScope();
        }
        /// <include file='doc\SoapProtocolImporter.uex' path='docs/doc[@for="SoapProtocolImporter.BeginClass"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override CodeTypeDeclaration BeginClass() {
            MethodNames.Clear();

            soapBinding = (SoapBinding)Binding.Extensions.Find(typeof(SoapBinding));
            transport = GetTransport(soapBinding.Transport);

            Type[] requiredTypes = new Type[] { typeof(SoapDocumentMethodAttribute), typeof(XmlAttributeAttribute), typeof(WebService), typeof(Object), typeof(DebuggerStepThroughAttribute), typeof(DesignerCategoryAttribute) };
            WebCodeGenerator.AddImports(this.CodeNamespace, WebCodeGenerator.GetNamespacesForTypes(requiredTypes));
            CodeFlags flags = 0;
            if (Style == ServiceDescriptionImportStyle.Server)
                flags = CodeFlags.IsAbstract;
            else if (Style == ServiceDescriptionImportStyle.ServerInterface)
                flags = CodeFlags.IsInterface;
            CodeTypeDeclaration codeClass = WebCodeGenerator.CreateClass(this.ClassName, null, 
                new string[0], null, CodeFlags.IsPublic | flags,
                ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));

            codeClass.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
            if (Style == ServiceDescriptionImportStyle.Client) {
                codeClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DebuggerStepThroughAttribute).FullName));
                codeClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DesignerCategoryAttribute).FullName, new CodeAttributeArgument[] { new CodeAttributeArgument(new CodePrimitiveExpression("code")) }));
            }
            else if (Style == ServiceDescriptionImportStyle.Server) {
                CodeAttributeDeclaration webService = new CodeAttributeDeclaration(typeof(WebServiceAttribute).FullName);
                string targetNs = Service != null ? Service.ServiceDescription.TargetNamespace : Binding.ServiceDescription.TargetNamespace;
                webService.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(targetNs)));
                codeClass.CustomAttributes.Add(webService);
            }

            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(WebServiceBindingAttribute).FullName);
            attribute.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(XmlConvert.DecodeName(Binding.Name))));
            attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(Binding.ServiceDescription.TargetNamespace)));

            codeClass.CustomAttributes.Add(attribute);

            codeClasses.Add(codeClass);
            classHeaders.Clear();
            return codeClass;
        }
Exemplo n.º 30
0
        public static void BasicHttpsBinding(
            TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
            WSMessageEncoding encoding, HttpClientCredentialType clientCred,
            AuthenticationSchemes authScheme, TestLabel label)
        {
            label.EnterScope("basicHttpsBinding");

            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");

            Assert.That(sd.Extensions, Is.Not.Null, label.Get());
            Assert.That(sd.Extensions.Count, Is.EqualTo(1), label.Get());
            Assert.That(sd.Extensions [0], Is.InstanceOfType(typeof(XmlElement)), label.Get());

            label.EnterScope("extensions");
            var extension = (XmlElement)sd.Extensions [0];

            Assert.That(extension.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
            Assert.That(extension.LocalName, Is.EqualTo("Policy"), label.Get());
            label.LeaveScope();

            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());
            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());
            label.LeaveScope();

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, WS.SoapBinding.HttpTransport, label);

            if (context.CheckPolicyXml)
            {
                label.EnterScope("policy-xml");
                Assert.That(xml, Is.Not.Null, label.Get());
                Assert.That(xml.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
                Assert.That(xml.LocalName, Is.EqualTo("PolicyReference"), label.Get());
                label.LeaveScope();
            }

            label.LeaveScope();              // wsdl

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);
            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            CheckBasicHttpBinding(
                bindings [0], "https", security, encoding,
                clientCred, authScheme, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);
            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            CheckEndpoint(endpoints [0], MetadataSamples.HttpsUri, label);
            label.LeaveScope();

            label.LeaveScope();
        }
Exemplo n.º 31
0
        bool ImportBasicHttpBinding(
            WsdlImporter importer, WsdlEndpointConversionContext context,
            CustomBinding custom, WS.SoapBinding soap)
        {
            TransportBindingElement           transportElement = null;
            MtomMessageEncodingBindingElement mtomElement      = null;
            TextMessageEncodingBindingElement textElement      = null;
            bool foundUnknownElement = false;

            foreach (var element in custom.Elements)
            {
                if (element is TransportBindingElement)
                {
                    transportElement = (TransportBindingElement)element;
                }
                else if (element is MtomMessageEncodingBindingElement)
                {
                    mtomElement = (MtomMessageEncodingBindingElement)element;
                }
                else if (element is TextMessageEncodingBindingElement)
                {
                    textElement = (TextMessageEncodingBindingElement)element;
                }
                else
                {
                    importer.AddWarning(
                        "Found unknown binding element `{0}' while attempting " +
                        "to import binding `{0}'.", element.GetType(),
                        custom.Name);
                    foundUnknownElement = true;
                }
            }

            if (foundUnknownElement)
            {
                return(false);
            }

            if ((mtomElement != null) && (textElement != null))
            {
                // FIXME: Should never happen
                importer.AddWarning(
                    "Found both MtomMessageEncodingBindingElement and " +
                    "TextMessageEncodingBindingElement while attempting to " +
                    "import binding `{0}'.", custom.Name);
                return(false);
            }

            BasicHttpBinding      httpBinding;
            AuthenticationSchemes authScheme;

            /*
             * FIXME: Maybe make the BasicHttpBinding use the transport element
             * that we created with the TransportBindingElementImporter ?
             *
             * There seems to be no public API to do that, so maybe add a private .ctor ?
             *
             */

            var httpsTransport = transportElement as HttpsTransportBindingElement;
            var httpTransport  = transportElement as HttpTransportBindingElement;

            if (httpsTransport != null)
            {
                httpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                authScheme  = httpsTransport.AuthenticationScheme;
            }
            else if (httpTransport != null)
            {
                authScheme = httpTransport.AuthenticationScheme;
                if ((authScheme != AuthenticationSchemes.None) &&
                    (authScheme != AuthenticationSchemes.Anonymous))
                {
                    httpBinding = new BasicHttpBinding(
                        BasicHttpSecurityMode.TransportCredentialOnly);
                }
                else
                {
                    httpBinding = new BasicHttpBinding();
                }
            }
            else
            {
                httpBinding = new BasicHttpBinding();
                authScheme  = AuthenticationSchemes.Anonymous;
            }

            if (mtomElement != null)
            {
                httpBinding.MessageEncoding = WSMessageEncoding.Mtom;
            }
            else if (textElement != null)
            {
                httpBinding.MessageEncoding = WSMessageEncoding.Text;
            }
            else
            {
                importer.AddWarning(
                    "Found neither MtomMessageEncodingBindingElement nor " +
                    "TextMessageEncodingBindingElement while attempting to " +
                    "import binding `{0}'.", custom.Name);
                return(false);
            }

            httpBinding.Name      = context.Endpoint.Binding.Name;
            httpBinding.Namespace = context.Endpoint.Binding.Namespace;

            switch (authScheme)
            {
            case AuthenticationSchemes.None:
            case AuthenticationSchemes.Anonymous:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                break;

            case AuthenticationSchemes.Basic:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                break;

            case AuthenticationSchemes.Digest:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Digest;
                break;

            case AuthenticationSchemes.Ntlm:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
                break;

            case AuthenticationSchemes.Negotiate:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                break;

            default:
                importer.AddWarning("Invalid auth scheme: {0}", authScheme);
                return(false);
            }

            if ((httpsTransport != null) && httpsTransport.RequireClientCertificate)
            {
                if (httpBinding.Security.Transport.ClientCredentialType != HttpClientCredentialType.None)
                {
                    importer.AddWarning("Cannot use both client certificate and explicit auth type.");
                    return(false);
                }
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            }

            context.Endpoint.Binding = httpBinding;
            return(true);
        }
 private static object GetSoapBinding(System.ServiceModel.Channels.Binding binding)
 {
     if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap11)
     {
         SoapBinding soapBinding = new SoapBinding();
         soapBinding.Transport = GetTransport(binding);
         soapBinding.Style = SoapBindingStyle.Document;
         return soapBinding;
     }
     else if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap12)
     {
         Soap12Binding soapBinding = new Soap12Binding();
         soapBinding.Transport = GetTransport(binding);
         soapBinding.Style = SoapBindingStyle.Document;
         return soapBinding;
     }
     return null;
 }
Exemplo n.º 33
0
        protected override CodeTypeDeclaration BeginClass()
        {
            soapBinding = (SoapBinding)Binding.Extensions.Find(typeof(SoapBinding));

            CodeTypeDeclaration codeClass = new CodeTypeDeclaration(ClassName);

#if NET_2_0
            codeClass.IsPartial = true;
#endif

            string location = null;

            if (Port != null)
            {
                SoapAddressBinding sab = (SoapAddressBinding)Port.Extensions.Find(typeof(SoapAddressBinding));
                if (sab != null)
                {
                    location = sab.Location;
                }
            }

            string namspace = (Port != null ? Port.Binding.Namespace : Binding.ServiceDescription.TargetNamespace);
            string name     = (Port != null ? Port.Name : Binding.Name);

            if (Style == ServiceDescriptionImportStyle.Client)
            {
                CodeTypeReference ctr = new CodeTypeReference("System.Web.Services.Protocols.SoapHttpClientProtocol");
                codeClass.BaseTypes.Add(ctr);
            }
            else
            {
                CodeTypeReference ctr = new CodeTypeReference("System.Web.Services.WebService");
                codeClass.BaseTypes.Add(ctr);
                CodeAttributeDeclaration attws = new CodeAttributeDeclaration("System.Web.Services.WebServiceAttribute");
                attws.Arguments.Add(GetArg("Namespace", namspace));
                AddCustomAttribute(codeClass, attws, true);
            }

            CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Web.Services.WebServiceBinding");
            att.Arguments.Add(GetArg("Name", name));
            att.Arguments.Add(GetArg("Namespace", namspace));
            AddCustomAttribute(codeClass, att, true);

            if (Style == ServiceDescriptionImportStyle.Client)
            {
                CodeConstructor cc = new CodeConstructor();
                cc.Attributes = MemberAttributes.Public;
                GenerateServiceUrl(location, cc.Statements);

#if NET_2_0
                if (ProtocolName.ToUpper() == "SOAP12")
                {
                    CodeExpression thisSoapVer = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
                    CodeFieldReferenceExpression soap12Enum =
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(SoapProtocolVersion)), "Soap12");
                    cc.Statements.Add(new CodeAssignStatement(thisSoapVer, soap12Enum));
                }
#endif
                codeClass.Members.Add(cc);
            }

            memberIds       = new CodeIdentifiers();
            headerVariables = new Hashtable();
            return(codeClass);
        }
Exemplo n.º 34
0
		protected override CodeTypeDeclaration BeginClass ()
		{
			soapBinding = (SoapBinding) Binding.Extensions.Find (typeof(SoapBinding));
			
			CodeTypeDeclaration codeClass = new CodeTypeDeclaration (ClassName);
#if NET_2_0
			codeClass.IsPartial = true;
#endif

			string location = null;
			
			if (Port != null) {
				SoapAddressBinding sab = (SoapAddressBinding) Port.Extensions.Find (typeof(SoapAddressBinding));
				if (sab != null) location = sab.Location;
			}
			
			string namspace = (Port != null ? Port.Binding.Namespace : Binding.ServiceDescription.TargetNamespace);
			string name = (Port != null ? Port.Name : Binding.Name);

			if (Style == ServiceDescriptionImportStyle.Client) {
				CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.SoapHttpClientProtocol");
				codeClass.BaseTypes.Add (ctr);
			}
			else {
				CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.WebService");
				codeClass.BaseTypes.Add (ctr);
				CodeAttributeDeclaration attws = new CodeAttributeDeclaration ("System.Web.Services.WebServiceAttribute");
				attws.Arguments.Add (GetArg ("Namespace", namspace));
				AddCustomAttribute (codeClass, attws, true);
			}
			
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebServiceBinding");
			att.Arguments.Add (GetArg ("Name", name));
			att.Arguments.Add (GetArg ("Namespace", namspace));
			AddCustomAttribute (codeClass, att, true);
	
			if (Style == ServiceDescriptionImportStyle.Client) {
				CodeConstructor cc = new CodeConstructor ();
				cc.Attributes = MemberAttributes.Public;
				GenerateServiceUrl (location, cc.Statements);

#if NET_2_0
				if (ProtocolName.ToUpper () == "SOAP12") {
					CodeExpression thisSoapVer = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), "SoapVersion");
					CodeFieldReferenceExpression soap12Enum =
						new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (typeof (SoapProtocolVersion)), "Soap12");
					cc.Statements.Add (new CodeAssignStatement (thisSoapVer, soap12Enum));
				}
#endif
				codeClass.Members.Add (cc);
			}
			
			memberIds = new CodeIdentifiers ();
			headerVariables = new Hashtable ();
			return codeClass;
		}
Exemplo n.º 35
0
        public static void NetTcpBinding(
            TestContext context, MetadataSet doc, SecurityMode security,
            bool reliableSession, TransferMode transferMode, TestLabel label)
        {
            label.EnterScope("netTcpBinding");

            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");

            label.EnterScope("extensions");
            Assert.That(sd.Extensions, Is.Not.Null, label.Get());
            Assert.That(sd.Extensions.Count, Is.EqualTo(1), label.Get());
            Assert.That(sd.Extensions [0], Is.InstanceOfType(typeof(XmlElement)), label.Get());

            var extension = (XmlElement)sd.Extensions [0];

            Assert.That(extension.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
            Assert.That(extension.LocalName, Is.EqualTo("Policy"), label.Get());
            label.LeaveScope();

            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());
            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, "http://schemas.microsoft.com/soap/tcp", label);

            if (context.CheckPolicyXml)
            {
                label.EnterScope("policy-xml");
                Assert.That(xml, Is.Not.Null, label.Get());

                Assert.That(xml.NamespaceURI, Is.EqualTo(WspNamespace), label.Get());
                Assert.That(xml.LocalName, Is.EqualTo("PolicyReference"), label.Get());
                label.LeaveScope();
            }

            label.LeaveScope();              // wsdl

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);
            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            CheckNetTcpBinding(
                bindings [0], security, reliableSession,
                transferMode, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);
            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            CheckEndpoint(endpoints [0], MetadataSamples.NetTcpUri, label);
            label.LeaveScope();

            label.LeaveScope();
        }
 /// <include file='doc\SoapProtocolImporter.uex' path='docs/doc[@for="SoapProtocolImporter.EndClass"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 protected override void EndClass() { 
     if (transport != null)
         transport.ImportClass();
     soapBinding = null;
 }
Exemplo n.º 37
0
        static void BasicHttpBinding_inner(
            TestContext context, MetadataSet doc, BasicHttpSecurityMode security,
            WSMessageEncoding encoding, HttpClientCredentialType clientCred,
            AuthenticationSchemes authScheme, bool isHttps, TestLabel label)
        {
            var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata;

            label.EnterScope("wsdl");
            label.EnterScope("bindings");
            Assert.That(sd.Bindings.Count, Is.EqualTo(1), label.Get());

            var binding = sd.Bindings [0];

            Assert.That(binding.ExtensibleAttributes, Is.Null, label.Get());
            Assert.That(binding.Extensions, Is.Not.Null, label.Get());

            bool hasPolicyXml;

            switch (security)
            {
            case BasicHttpSecurityMode.None:
                if (isHttps)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = encoding == WSMessageEncoding.Mtom;
                break;

            case BasicHttpSecurityMode.Message:
            case BasicHttpSecurityMode.Transport:
            case BasicHttpSecurityMode.TransportWithMessageCredential:
                if (encoding == WSMessageEncoding.Mtom)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = true;
                break;

            case BasicHttpSecurityMode.TransportCredentialOnly:
                if (isHttps)
                {
                    throw new InvalidOperationException();
                }
                hasPolicyXml = true;
                break;

            default:
                throw new InvalidOperationException();
            }
            label.LeaveScope();

            WS.SoapBinding soap = null;
            XmlElement     xml  = null;

            foreach (var ext in binding.Extensions)
            {
                if (ext is WS.SoapBinding)
                {
                    soap = (WS.SoapBinding)ext;
                }
                else if (ext is XmlElement)
                {
                    xml = (XmlElement)ext;
                }
            }

            CheckSoapBinding(soap, WS.SoapBinding.HttpTransport, label);
            label.LeaveScope();

            label.EnterScope("policy-xml");
            if (!hasPolicyXml)
            {
                Assert.That(xml, Is.Null, label.Get());
            }
            else
            {
                Assert.That(xml, Is.Not.Null, label.Get());
                var assertions = AssertPolicy(sd, xml, label);
                Assert.That(assertions, Is.Not.Null, label.Get());
                if (clientCred == HttpClientCredentialType.Ntlm)
                {
                    AssertPolicy(assertions, NtlmAuthenticationQName, label);
                }
                if (encoding == WSMessageEncoding.Mtom)
                {
                    AssertPolicy(assertions, MtomEncodingQName, label);
                }
                switch (security)
                {
                case BasicHttpSecurityMode.Message:
                    AssertPolicy(assertions, AsymmetricBindingQName, label);
                    AssertPolicy(assertions, Wss10QName, label);
                    break;

                case BasicHttpSecurityMode.Transport:
                    AssertPolicy(assertions, TransportBindingQName, label);
                    break;

                case BasicHttpSecurityMode.TransportWithMessageCredential:
                    AssertPolicy(assertions, SignedSupportingQName, label);
                    AssertPolicy(assertions, TransportBindingQName, label);
                    AssertPolicy(assertions, Wss10QName, label);
                    break;

                default:
                    break;
                }
                Assert.That(assertions.Count, Is.EqualTo(0), label.Get());
            }
            label.LeaveScope();

            label.EnterScope("services");
            Assert.That(sd.Services, Is.Not.Null, label.Get());
            Assert.That(sd.Services.Count, Is.EqualTo(1), label.Get());
            var service = sd.Services [0];

            Assert.That(service.Ports, Is.Not.Null, label.Get());
            Assert.That(service.Ports.Count, Is.EqualTo(1), label.Get());
            var port = service.Ports [0];

            label.EnterScope("port");
            Assert.That(port.Extensions, Is.Not.Null, label.Get());
            Assert.That(port.Extensions.Count, Is.EqualTo(1), label.Get());

            WS.SoapAddressBinding soap_addr_binding = null;
            foreach (var extension in port.Extensions)
            {
                if (extension is WS.SoapAddressBinding)
                {
                    soap_addr_binding = (WS.SoapAddressBinding)extension;
                }
                else
                {
                    Assert.Fail(label.Get());
                }
            }
            Assert.That(soap_addr_binding, Is.Not.Null, label.Get());
            label.LeaveScope();

            label.LeaveScope();              // wsdl

            var importer = new WsdlImporter(doc);

            label.EnterScope("bindings");
            var bindings = importer.ImportAllBindings();

            CheckImportErrors(importer, label);

            Assert.That(bindings, Is.Not.Null, label.Get());
            Assert.That(bindings.Count, Is.EqualTo(1), label.Get());

            string scheme;

            if ((security == BasicHttpSecurityMode.Transport) ||
                (security == BasicHttpSecurityMode.TransportWithMessageCredential))
            {
                scheme = "https";
            }
            else
            {
                scheme = "http";
            }

            CheckBasicHttpBinding(
                bindings [0], scheme, security, encoding, clientCred,
                authScheme, label);
            label.LeaveScope();

            label.EnterScope("endpoints");
            var endpoints = importer.ImportAllEndpoints();

            CheckImportErrors(importer, label);

            Assert.That(endpoints, Is.Not.Null, label.Get());
            Assert.That(endpoints.Count, Is.EqualTo(1), label.Get());

            var uri = isHttps ? MetadataSamples.HttpsUri : MetadataSamples.HttpUri;

            CheckEndpoint(endpoints [0], uri, label);
            label.LeaveScope();
        }
        public override void Check(ConformanceCheckContext ctx, Binding value)
        {
            SoapBinding sb = (SoapBinding)value.Extensions.Find(typeof(SoapBinding));

            if (sb == null)
            {
                return;
            }

            if (sb.Transport == null || sb.Transport == "")
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2701);
                return;
            }

            if (sb.Transport != "http://schemas.xmlsoap.org/soap/http")
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2702);
            }

            LiteralType type = GetLiteralBindingType(value);

            if (type == LiteralType.NotLiteral)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2706);
            }
            else if (type == LiteralType.Inconsistent)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2705);
            }

            // Collect all parts referenced from this type

            Hashtable parts = new Hashtable();
            PortType  port  = ctx.Services.GetPortType(value.Type);

            foreach (Operation op in port.Operations)
            {
                foreach (OperationMessage om in op.Messages)
                {
                    Message msg = ctx.Services.GetMessage(om.Message);
                    foreach (MessagePart part in msg.Parts)
                    {
                        parts [part] = part; // do not use Add() - there could be the same MessagePart instance.
                    }
                }
            }

            foreach (OperationBinding ob in value.Operations)
            {
                if (ob.Input != null)
                {
                    CheckMessageBinding(ctx, parts, ob.Input);
                }
                if (ob.Output != null)
                {
                    CheckMessageBinding(ctx, parts, ob.Output);
                }
                foreach (FaultBinding fb in ob.Faults)
                {
                    CheckMessageBinding(ctx, parts, fb);
                }
            }

            if (parts.Count > 0)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2209);
            }

            // check existence of corresponding operation in portType for each binding operation
            if (CheckCorrespondingOperationsForBinding(ctx, value, port))
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2718);
            }

            // check duplicate operation signature.
            ArrayList sigs = new ArrayList();

            foreach (OperationBinding ob in value.Operations)
            {
                if (sigs.Contains(ob.Name))
                {
                    ctx.ReportRuleViolation(value, BasicProfileRules.R2710);
                }
                sigs.Add(ob.Name);
            }

            // check namespace declarations.
            switch (type)
            {
            case LiteralType.Document:
            case LiteralType.Rpc:
                CheckSoapBindingExtensions(ctx, value, type);
                break;
            }
        }
Exemplo n.º 39
0
 void SetBinding(SoapBinding soapBinding)
 {
     this.soapBinding = soapBinding;
 }
        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);
            }
        }