public SoapDocumentationHandler (Type type, HttpContext context): base (type)
		{
			_url = context.Request.Url.ToString();
			int i = _url.IndexOf ('?');
			if (i != -1) _url = _url.Substring (0,i);
			_typeStubInfo = (SoapTypeStubInfo) TypeStubManager.GetTypeStub (ServiceType, "Soap");
			
			HttpRequest req = context.Request;
			string key = null;
			if (req.QueryString.Count == 1) {
				key = req.QueryString.GetKey (0);
				if (key == null)
					key = req.QueryString [0];

				if (key != null)
					key = key.ToLower (CultureInfo.InvariantCulture);
			}
				
			if (key == "wsdl" || key == "schema" || key == "code" || key == "disco")
				return;
				
#if NET_2_0
			string help = WebServicesSection.Current.WsdlHelpGenerator.Href;
			string path = Path.GetDirectoryName (ConfigurationManager.OpenMachineConfiguration().FilePath);
#else
			string help = WSConfig.Instance.WsdlHelpPage;
			string path = Path.GetDirectoryName (WSConfig.Instance.ConfigFilePath);
#endif
			string appPath = AppDomain.CurrentDomain.GetData (".appPath").ToString ();
			string vpath;
			if (path.StartsWith (appPath)) {
				vpath = path.Substring (appPath.Length);
				vpath = vpath.Replace ("\\", "/");
			} else {
				vpath = "/";
			}

			if (vpath.EndsWith ("/"))
				vpath += help;
			else
				vpath += "/" + help;

			string physPath = Path.Combine (path, help);
			
#if !TARGET_JVM
			if (!File.Exists (physPath))
				throw new InvalidOperationException ("Documentation page '" + physPath + "' not found");
#endif

			_pageHandler = PageParser.GetCompiledPageInstance (vpath, physPath, context);
		}
        public SoapDocumentationHandler(Type type, HttpContext context) : base(type)
        {
            _url = context.Request.Url.ToString();
            int i = _url.LastIndexOf('?');

            if (i != -1)
            {
                _url = _url.Substring(0, i);
            }
            _typeStubInfo = (SoapTypeStubInfo)TypeStubManager.GetTypeStub(ServiceType, "Soap");

            HttpRequest req = context.Request;
            string      key = null;

            if (req.QueryString.Count == 1)
            {
                key = req.QueryString.GetKey(0);
                if (key == null)
                {
                    key = req.QueryString [0];
                }

                if (key != null)
                {
                    key = key.ToLower(CultureInfo.InvariantCulture);
                }
            }

            if (key == "wsdl" || key == "schema" || key == "code" || key == "disco")
            {
                return;
            }

#if NET_2_0
            string help = WebServicesSection.Current.WsdlHelpGenerator.Href;
            string path = Path.GetDirectoryName(ConfigurationManager.OpenMachineConfiguration().FilePath);
#else
            string help = WSConfig.Instance.WsdlHelpPage;
            string path = Path.GetDirectoryName(WSConfig.Instance.ConfigFilePath);
#endif
            string appPath = AppDomain.CurrentDomain.GetData(".appPath").ToString();
            string vpath;
            if (path.StartsWith(appPath))
            {
                vpath = path.Substring(appPath.Length);
                vpath = vpath.Replace("\\", "/");
            }
            else
            {
                vpath = "/";
            }

            if (vpath.EndsWith("/"))
            {
                vpath += help;
            }
            else
            {
                vpath += "/" + help;
            }

            string physPath = Path.Combine(path, help);

#if !TARGET_JVM
            if (!File.Exists(physPath))
            {
                throw new InvalidOperationException("Documentation page '" + physPath + "' not found");
            }
#endif

            _pageHandler = PageParser.GetCompiledPageInstance(vpath, physPath, context);
        }
		public SoapHttpClientProtocol () 
		{
			type_info = (SoapTypeStubInfo) TypeStubManager.GetTypeStub (this.GetType (), "Soap");
		}
Beispiel #4
0
        //
        // Constructor
        //
        public SoapMethodStubInfo(TypeStubInfo typeStub, LogicalMethodInfo source, object kind, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter)
            : base(typeStub, source)
        {
            SoapTypeStubInfo    parent      = (SoapTypeStubInfo)typeStub;
            XmlElementAttribute optional_ns = null;

            if (kind == null)
            {
                Use               = parent.LogicalType.BindingUse;
                RequestName       = "";
                RequestNamespace  = "";
                ResponseName      = "";
                ResponseNamespace = "";
                ParameterStyle    = parent.ParameterStyle;
                SoapBindingStyle  = parent.SoapBindingStyle;
                OneWay            = false;
// disabled (see bug #332150)
//#if NET_2_0
//				if (parent.Type != source.DeclaringType)
//					Binding = source.DeclaringType.Name + parent.ProtocolName;
//#endif
            }
            else if (kind is SoapDocumentMethodAttribute)
            {
                SoapDocumentMethodAttribute dma = (SoapDocumentMethodAttribute)kind;

                Use = dma.Use;
                if (Use == SoapBindingUse.Default)
                {
                    if (parent.SoapBindingStyle == SoapBindingStyle.Document)
                    {
                        Use = parent.LogicalType.BindingUse;
                    }
                    else
                    {
                        Use = SoapBindingUse.Literal;
                    }
                }

                Action            = dma.Action;
                Binding           = dma.Binding;
                RequestName       = dma.RequestElementName;
                RequestNamespace  = dma.RequestNamespace;
                ResponseName      = dma.ResponseElementName;
                ResponseNamespace = dma.ResponseNamespace;
                ParameterStyle    = dma.ParameterStyle;
                if (ParameterStyle == SoapParameterStyle.Default)
                {
                    ParameterStyle = parent.ParameterStyle;
                }
                OneWay           = dma.OneWay;
                SoapBindingStyle = SoapBindingStyle.Document;
            }
            else
            {
                SoapRpcMethodAttribute rma = (SoapRpcMethodAttribute)kind;
                Use = SoapBindingUse.Encoded;                   // RPC always use encoded

                Action = rma.Action;
                if (Action != null && Action.Length == 0)
                {
                    Action = null;
                }
                Binding = rma.Binding;

                // When using RPC, MS.NET seems to ignore RequestElementName and
                // MessageName, and it always uses the method name
                RequestName  = source.Name;
                ResponseName = source.Name + "Response";
//				RequestName = rma.RequestElementName;
//				ResponseName = rma.ResponseElementName;
                RequestNamespace  = rma.RequestNamespace;
                ResponseNamespace = rma.ResponseNamespace;
                ParameterStyle    = SoapParameterStyle.Wrapped;
                OneWay            = rma.OneWay;
                SoapBindingStyle  = SoapBindingStyle.Rpc;

                // For RPC calls, make all arguments be part of the empty namespace
                optional_ns           = new XmlElementAttribute();
                optional_ns.Namespace = "";
            }

            if (OneWay)
            {
                if (source.ReturnType != typeof(void))
                {
                    throw new Exception("OneWay methods should not have a return value.");
                }
                if (source.OutParameters.Length != 0)
                {
                    throw new Exception("OneWay methods should not have out/ref parameters.");
                }
            }

            BindingInfo binfo = parent.GetBinding(Binding);

            if (binfo == null)
            {
                throw new InvalidOperationException("Type '" + parent.Type + "' is missing WebServiceBinding attribute that defines a binding named '" + Binding + "'.");
            }

            string serviceNamespace = binfo.Namespace;

            if (RequestNamespace == "")
            {
                RequestNamespace = parent.LogicalType.GetWebServiceNamespace(serviceNamespace, Use);
            }
            if (ResponseNamespace == "")
            {
                ResponseNamespace = parent.LogicalType.GetWebServiceNamespace(serviceNamespace, Use);
            }
            if (RequestName == "")
            {
                RequestName = Name;
            }
            if (ResponseName == "")
            {
                ResponseName = Name + "Response";
            }
            if (Action == null)
            {
                Action = serviceNamespace.EndsWith("/") ? (serviceNamespace + Name) : (serviceNamespace + "/" + Name);
            }

            bool hasWrappingElem = (ParameterStyle == SoapParameterStyle.Wrapped);
            bool writeAccessors  = (SoapBindingStyle == SoapBindingStyle.Rpc);

            XmlReflectionMember [] in_members  = BuildRequestReflectionMembers(optional_ns);
            XmlReflectionMember [] out_members = BuildResponseReflectionMembers(optional_ns);

            if (Use == SoapBindingUse.Literal)
            {
                xmlImporter.IncludeTypes(source.CustomAttributeProvider);
                InputMembersMapping  = xmlImporter.ImportMembersMapping(RequestName, RequestNamespace, in_members, hasWrappingElem);
                OutputMembersMapping = xmlImporter.ImportMembersMapping(ResponseName, ResponseNamespace, out_members, hasWrappingElem);
            }
            else
            {
                soapImporter.IncludeTypes(source.CustomAttributeProvider);
                InputMembersMapping  = soapImporter.ImportMembersMapping(RequestName, RequestNamespace, in_members, hasWrappingElem, writeAccessors);
                OutputMembersMapping = soapImporter.ImportMembersMapping(ResponseName, ResponseNamespace, out_members, hasWrappingElem, writeAccessors);
            }

            requestSerializerId  = parent.RegisterSerializer(InputMembersMapping);
            responseSerializerId = parent.RegisterSerializer(OutputMembersMapping);

            object[]  o               = source.GetCustomAttributes(typeof(SoapHeaderAttribute));
            ArrayList allHeaderList   = new ArrayList(o.Length);
            ArrayList inHeaderList    = new ArrayList(o.Length);
            ArrayList outHeaderList   = new ArrayList(o.Length);
            ArrayList faultHeaderList = new ArrayList();

            SoapHeaderDirection unknownHeaderDirections = (SoapHeaderDirection)0;

            for (int i = 0; i < o.Length; i++)
            {
                SoapHeaderAttribute att  = (SoapHeaderAttribute)o[i];
                MemberInfo[]        mems = source.DeclaringType.GetMember(att.MemberName);
                if (mems.Length == 0)
                {
                    throw new InvalidOperationException("Member " + att.MemberName + " not found in class " + source.DeclaringType.FullName + ".");
                }

                HeaderInfo header = new HeaderInfo(mems[0], att);
                allHeaderList.Add(header);
                if (!header.Custom)
                {
                    if ((header.Direction & SoapHeaderDirection.In) != 0)
                    {
                        inHeaderList.Add(header);
                    }
                    if ((header.Direction & SoapHeaderDirection.Out) != 0)
                    {
                        outHeaderList.Add(header);
                    }
                    if ((header.Direction & SoapHeaderDirection.Fault) != 0)
                    {
                        faultHeaderList.Add(header);
                    }
                }
                else
                {
                    unknownHeaderDirections |= header.Direction;
                }
            }

            Headers = (HeaderInfo[])allHeaderList.ToArray(typeof(HeaderInfo));

            if (inHeaderList.Count > 0 || (unknownHeaderDirections & SoapHeaderDirection.In) != 0)
            {
                InHeaders = (HeaderInfo[])inHeaderList.ToArray(typeof(HeaderInfo));
                XmlReflectionMember[] members = BuildHeadersReflectionMembers(InHeaders);

                if (Use == SoapBindingUse.Literal)
                {
                    InputHeaderMembersMapping = xmlImporter.ImportMembersMapping("", RequestNamespace, members, false);
                }
                else
                {
                    InputHeaderMembersMapping = soapImporter.ImportMembersMapping("", RequestNamespace, members, false, false);
                }

                requestHeadersSerializerId = parent.RegisterSerializer(InputHeaderMembersMapping);
            }

            if (outHeaderList.Count > 0 || (unknownHeaderDirections & SoapHeaderDirection.Out) != 0)
            {
                OutHeaders = (HeaderInfo[])outHeaderList.ToArray(typeof(HeaderInfo));
                XmlReflectionMember[] members = BuildHeadersReflectionMembers(OutHeaders);

                if (Use == SoapBindingUse.Literal)
                {
                    OutputHeaderMembersMapping = xmlImporter.ImportMembersMapping("", RequestNamespace, members, false);
                }
                else
                {
                    OutputHeaderMembersMapping = soapImporter.ImportMembersMapping("", RequestNamespace, members, false, false);
                }

                responseHeadersSerializerId = parent.RegisterSerializer(OutputHeaderMembersMapping);
            }

            if (faultHeaderList.Count > 0 || (unknownHeaderDirections & SoapHeaderDirection.Fault) != 0)
            {
                FaultHeaders = (HeaderInfo[])faultHeaderList.ToArray(typeof(HeaderInfo));
                XmlReflectionMember[] members = BuildHeadersReflectionMembers(FaultHeaders);

                if (Use == SoapBindingUse.Literal)
                {
                    FaultHeaderMembersMapping = xmlImporter.ImportMembersMapping("", RequestNamespace, members, false);
                }
                else
                {
                    FaultHeaderMembersMapping = soapImporter.ImportMembersMapping("", RequestNamespace, members, false, false);
                }

                faultHeadersSerializerId = parent.RegisterSerializer(FaultHeaderMembersMapping);
            }

            SoapExtensions = SoapExtension.GetMethodExtensions(source);
        }
Beispiel #5
0
 public SoapHttpClientProtocol()
 {
     type_info = (SoapTypeStubInfo)TypeStubManager.GetTypeStub(this.GetType(), "Soap");
 }
 public HttpSoapWebServiceHandler(Type type) : base(type)
 {
     _typeStubInfo = (SoapTypeStubInfo)TypeStubManager.GetTypeStub(ServiceType, "Soap");
 }
		public HttpSoapWebServiceHandler (Type type): base (type)
		{
			_typeStubInfo = (SoapTypeStubInfo) TypeStubManager.GetTypeStub (ServiceType, "Soap");
		}
		static SoapHeaderCollection ReadHeaders (SoapTypeStubInfo typeStubInfo, SoapBindingUse methodUse, XmlTextReader xmlReader)
		{
			SoapHeaderCollection headers = new SoapHeaderCollection ();
			while (! (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Body" && xmlReader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace))
			{
				if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Header" 
				    && xmlReader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace && !xmlReader.IsEmptyElement)
				{
					xmlReader.ReadStartElement ();
					xmlReader.MoveToContent ();
					
					while (xmlReader.NodeType != XmlNodeType.Element && xmlReader.NodeType != XmlNodeType.EndElement)
						xmlReader.Skip ();
						
					xmlReader.MoveToContent ();
					
					if (xmlReader.NodeType == XmlNodeType.Element) {
						XmlQualifiedName qname = new XmlQualifiedName (xmlReader.LocalName, xmlReader.NamespaceURI);
						XmlSerializer headerSerializer = typeStubInfo.GetHeaderSerializer (qname, methodUse);
						if (headerSerializer != null)
						{
							SoapHeader header = (SoapHeader) headerSerializer.Deserialize (xmlReader);
							headers.Add (header);
						}
						else
						{
							XmlDocument doc = new XmlDocument ();
							XmlElement elem = (XmlElement) doc.ReadNode (xmlReader);
							headers.Add (new SoapUnknownHeader (elem));
						}
					}
					
					while (xmlReader.NodeType != XmlNodeType.EndElement)
						xmlReader.Skip ();
						
					xmlReader.ReadEndElement ();
				}
				else
					xmlReader.Skip ();
			}
			return headers;
		}
		public static void ReadSoapMessage (XmlTextReader xmlReader, SoapTypeStubInfo typeStubInfo, SoapBindingUse methodUse, XmlSerializer bodySerializer, out object body, out SoapHeaderCollection headers)
		{
			xmlReader.MoveToContent ();
			xmlReader.ReadStartElement ("Envelope", WebServiceHelper.SoapEnvelopeNamespace);

			headers = ReadHeaders (typeStubInfo, methodUse, xmlReader);

			xmlReader.MoveToContent ();
			xmlReader.ReadStartElement ("Body", WebServiceHelper.SoapEnvelopeNamespace);
			xmlReader.MoveToContent ();
			
			if (xmlReader.LocalName == "Fault" && xmlReader.NamespaceURI == SoapEnvelopeNamespace)
				bodySerializer = Fault.Serializer;

			body = bodySerializer.Deserialize (xmlReader);
		}
		public static void WriteSoapMessage (XmlTextWriter xtw, SoapTypeStubInfo info, SoapBindingUse methodUse, XmlSerializer bodySerializer, object bodyContent, SoapHeaderCollection headers)
		{
			xtw.WriteStartDocument ();
			xtw.WriteStartElement ("soap", "Envelope", WebServiceHelper.SoapEnvelopeNamespace);
			xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
			xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);

			// Serialize headers
			if (headers != null)
			{
				foreach (SoapHeader header in headers) 
				{
					XmlSerializer ser = info.GetHeaderSerializer (header.GetType(), methodUse);
					xtw.WriteStartElement ("soap", "Header", WebServiceHelper.SoapEnvelopeNamespace);
					ser.Serialize (xtw, header);
					xtw.WriteEndElement ();
				}
			}

			// Serialize body
			xtw.WriteStartElement ("soap", "Body", WebServiceHelper.SoapEnvelopeNamespace);
			
			if (methodUse == SoapBindingUse.Encoded)
				xtw.WriteAttributeString ("encodingStyle", WebServiceHelper.SoapEnvelopeNamespace, "http://schemas.xmlsoap.org/soap/encoding/");
				
			bodySerializer.Serialize (xtw, bodyContent);

			xtw.WriteEndElement ();
			xtw.WriteEndElement ();
			xtw.Flush ();
		}