コード例 #1
0
		bool ImportNetTcpBinding (
			WsdlImporter importer, WsdlEndpointConversionContext context,
			CustomBinding custom, WS.Soap12Binding soap)
		{
			TcpTransportBindingElement transportElement = null;
			BinaryMessageEncodingBindingElement binaryElement = null;
			TransactionFlowBindingElement transactionFlowElement = null;
			WindowsStreamSecurityBindingElement windowsStreamElement = null;
			SslStreamSecurityBindingElement sslStreamElement = null;
			bool foundUnknownElement = false;
			
			foreach (var element in custom.Elements) {
				if (element is TcpTransportBindingElement)
					transportElement = (TcpTransportBindingElement)element;
				else if (element is BinaryMessageEncodingBindingElement)
					binaryElement = (BinaryMessageEncodingBindingElement)element;
				else if (element is TransactionFlowBindingElement)
					transactionFlowElement = (TransactionFlowBindingElement)element;
				else if (element is WindowsStreamSecurityBindingElement)
					windowsStreamElement = (WindowsStreamSecurityBindingElement)element;
				else if (element is SslStreamSecurityBindingElement)
					sslStreamElement = (SslStreamSecurityBindingElement)element;
				else {
					importer.AddWarning (
						"Found unknown binding element `{0}' while importing " +
						"binding `{1}'.", element.GetType (), custom.Name);
					foundUnknownElement = true;
				}
			}

			if (foundUnknownElement)
				return false;

			if (transportElement == null) {
				importer.AddWarning (
					"Missing TcpTransportBindingElement while importing " +
					"binding `{0}'.", custom.Name);
				return false;
			}
			if (binaryElement == null) {
				importer.AddWarning (
					"Missing BinaryMessageEncodingBindingElement while importing " +
					"binding `{0}'.", custom.Name);
				return false;
			}

			if ((windowsStreamElement != null) && (sslStreamElement != null)) {
				importer.AddWarning (
					"Found both WindowsStreamSecurityBindingElement and " +
					"SslStreamSecurityBindingElement while importing binding `{0}.",
					custom.Name);
				return false;
			}

			NetTcpSecurity security;
			if (windowsStreamElement != null) {
				security = new NetTcpSecurity (SecurityMode.Transport);
				security.Transport.ProtectionLevel = windowsStreamElement.ProtectionLevel;
			} else if (sslStreamElement != null) {
				security = new NetTcpSecurity (SecurityMode.TransportWithMessageCredential);
			} else {
				security = new NetTcpSecurity (SecurityMode.None);
			}

			var netTcp = new NetTcpBinding (transportElement, security, false);

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

			context.Endpoint.Binding = netTcp;
			return true;
		}
コード例 #2
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;
		}