public static void Main() { // <Snippet1> // <Snippet2> // Get the type for the proxy class MyMath Web service. // Note: The MyMath class is a proxy class generated by the Wsdl.exe // utility for the Math Web service. This class can also be found in // the SoapHttpClientProtocol class example. Type myType = typeof(MyMath.MyMath); MethodInfo myBeginMethod = myType.GetMethod("BeginAdd"); MethodInfo myEndMethod = myType.GetMethod("EndAdd"); MethodInfo myMethod = myType.GetMethod("Add"); Console.WriteLine("Is 'BeginAdd' a Begin Method : " + LogicalMethodInfo.IsBeginMethod(myBeginMethod).ToString()); Console.WriteLine("Is 'Add' a Begin Method : " + LogicalMethodInfo.IsBeginMethod(myMethod).ToString()); Console.WriteLine("Is 'EndAdd' an End Method : " + LogicalMethodInfo.IsEndMethod(myEndMethod).ToString()); // </Snippet1> // </Snippet2> }
internal override bool ReflectReturn() { MessagePart part = new MessagePart(); part.Name = "Body"; ReflectionContext.OutputMessage.Parts.Add(part); if (typeof(XmlNode).IsAssignableFrom(ReflectionContext.Method.ReturnType)) { MimeContentBinding mimeContentBinding = new MimeContentBinding(); mimeContentBinding.Type = "text/xml"; mimeContentBinding.Part = part.Name; ReflectionContext.OperationBinding.Output.Extensions.Add(mimeContentBinding); } else { MimeXmlBinding mimeXmlBinding = new MimeXmlBinding(); mimeXmlBinding.Part = part.Name; LogicalMethodInfo methodInfo = ReflectionContext.Method; XmlAttributes a = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider); XmlTypeMapping xmlTypeMapping = ReflectionContext.ReflectionImporter.ImportTypeMapping(methodInfo.ReturnType, a.XmlRoot); xmlTypeMapping.SetKey(methodInfo.GetKey() + ":Return"); ReflectionContext.SchemaExporter.ExportTypeMapping(xmlTypeMapping); part.Element = new XmlQualifiedName(xmlTypeMapping.XsdElementName, xmlTypeMapping.Namespace); ReflectionContext.OperationBinding.Output.Extensions.Add(mimeXmlBinding); } return(true); }
public HttpGetMethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source): base (parent, source) { ParameterReaderType = new MimeFormatterInfo (typeof(UrlParameterReader)); ReturnWriterType = new MimeFormatterInfo (typeof(XmlReturnWriter)); if (ParameterWriterType == null) ParameterWriterType = new MimeFormatterInfo (typeof(UrlParameterWriter)); }
internal override bool ReflectReturn() { MessagePart messagePart = new MessagePart { Name = "Body" }; base.ReflectionContext.OutputMessage.Parts.Add(messagePart); if (typeof(XmlNode).IsAssignableFrom(base.ReflectionContext.Method.ReturnType)) { MimeContentBinding extension = new MimeContentBinding { Type = "text/xml", Part = messagePart.Name }; base.ReflectionContext.OperationBinding.Output.Extensions.Add(extension); } else { MimeXmlBinding binding2 = new MimeXmlBinding { Part = messagePart.Name }; LogicalMethodInfo method = base.ReflectionContext.Method; XmlAttributes attributes = new XmlAttributes(method.ReturnTypeCustomAttributeProvider); XmlTypeMapping xmlTypeMapping = base.ReflectionContext.ReflectionImporter.ImportTypeMapping(method.ReturnType, attributes.XmlRoot); xmlTypeMapping.SetKey(method.GetKey() + ":Return"); base.ReflectionContext.SchemaExporter.ExportTypeMapping(xmlTypeMapping); messagePart.Element = new XmlQualifiedName(xmlTypeMapping.XsdElementName, xmlTypeMapping.Namespace); base.ReflectionContext.OperationBinding.Output.Extensions.Add(binding2); } return(true); }
static void Run() { Type myType = typeof(MyService); MethodInfo myMethodInfo = myType.GetMethod("Add"); LogicalMethodInfo myLogicalMethodInfo = new LogicalMethodInfo(myMethodInfo); Console.WriteLine("\nPrinting properties of method : {0}\n", myLogicalMethodInfo.ToString()); Console.WriteLine("\nThe declaring type of the method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.DeclaringType); Console.WriteLine("\nThe parameters of the method {0} are :\n", myLogicalMethodInfo.Name); ParameterInfo[] myParameters = myLogicalMethodInfo.Parameters; for (int i = 0; i < myParameters.Length; i++) { Console.WriteLine("\t" + myParameters[i].Name + " : " + myParameters[i].ParameterType); } Console.WriteLine("\nThe return type of the method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.ReturnType); MyService service = new MyService(); Console.WriteLine("\nInvoking the method {0}\n", myLogicalMethodInfo.Name); Console.WriteLine("\tThe sum of 10 and 10 is : {0}", myLogicalMethodInfo.Invoke(service, new object[] { 10, 10 })); }
public override object GetInitializer( LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { //return null; return(((ReverserExtensionAttribute)attribute).Filename); }
// </Snippet1> public override object GetInitializer(LogicalMethodInfo lmi, SoapExtensionAttribute sea) { // method added so sample will compile object myobject = new Object(); return(myobject); }
internal static WebServiceBindingAttribute GetAttribute(LogicalMethodInfo methodInfo, string binding) { if (methodInfo.Binding != null) { if (binding.Length > 0 && methodInfo.Binding.Name != binding) { throw new InvalidOperationException(Res.GetString(Res.WebInvalidBindingName, binding, methodInfo.Binding.Name)); } return(methodInfo.Binding); } Type type = methodInfo.DeclaringType; object[] attrs = type.GetCustomAttributes(typeof(WebServiceBindingAttribute), false); WebServiceBindingAttribute webAttr = null; foreach (WebServiceBindingAttribute attr in attrs) { if (attr.Name == binding) { if (webAttr != null) { throw new ArgumentException(Res.GetString(Res.MultipleBindingsWithSameName2, type.FullName, binding, "methodInfo")); } webAttr = attr; } } if (webAttr == null && binding != null && binding.Length > 0) { throw new ArgumentException(Res.GetString(Res.TypeIsMissingWebServiceBindingAttributeThat2, type.FullName, binding), "methodInfo"); } return(webAttr); }
/// <summary> /// Used to get the initializer object for SOAP extension that /// is configured for entire web serice. /// </summary> /// <param name="methodInfo">Method being processed, if there is one</param> /// <param name="attribute">Attribute being processed</param> /// <returns>Object that will be passed to code that processes web method invocations</returns> public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { Argument.Assert.IsNotNull(methodInfo, "methodInfo"); Argument.Assert.IsNotNull(attribute, "attribute"); return(GetInitializerHelper(methodInfo.DeclaringType, methodInfo, attribute)); }
internal static WebServiceBindingAttribute GetAttribute(LogicalMethodInfo methodInfo, string binding) { if (methodInfo.Binding != null) { if ((binding.Length > 0) && (methodInfo.Binding.Name != binding)) { throw new InvalidOperationException(Res.GetString("WebInvalidBindingName", new object[] { binding, methodInfo.Binding.Name })); } return(methodInfo.Binding); } Type declaringType = methodInfo.DeclaringType; object[] customAttributes = declaringType.GetCustomAttributes(typeof(WebServiceBindingAttribute), false); WebServiceBindingAttribute attribute = null; foreach (WebServiceBindingAttribute attribute2 in customAttributes) { if (attribute2.Name == binding) { if (attribute != null) { throw new ArgumentException(Res.GetString("MultipleBindingsWithSameName2", new object[] { declaringType.FullName, binding, "methodInfo" })); } attribute = attribute2; } } if (((attribute == null) && (binding != null)) && (binding.Length > 0)) { throw new ArgumentException(Res.GetString("TypeIsMissingWebServiceBindingAttributeThat2", new object[] { declaringType.FullName, binding }), "methodInfo"); } return(attribute); }
public static void Main() { Type myType = typeof(MyService); MethodInfo myMethodInfo = myType.GetMethod("Add"); // Create a synchronous 'LogicalMethodInfo' instance. LogicalMethodInfo myLogicalMethodInfo = (LogicalMethodInfo.Create(new MethodInfo[] { myMethodInfo }, LogicalMethodTypes.Sync))[0]; // Display the method for which the attributes are being displayed. Console.WriteLine("\nDisplaying the attributes for the method : {0}\n", myLogicalMethodInfo.MethodInfo); // Displaying a custom attribute of type 'MyAttribute' Console.WriteLine("\nDisplaying attribute of type 'MyAttribute'\n"); object attribute = myLogicalMethodInfo.GetCustomAttribute(typeof(MyAttribute)); Console.WriteLine(((MyAttribute)attribute).Name); // Display all custom attribute of type 'MyAttribute'. Console.WriteLine("\nDisplaying all attributes of type 'MyAttribute'\n"); object[] attributes = myLogicalMethodInfo.GetCustomAttributes(typeof(MyAttribute)); for (int i = 0; i < attributes.Length; i++) { Console.WriteLine(((MyAttribute)attributes[i]).Name); } // Display all return attributes of type 'MyAttribute'. Console.WriteLine("\nDisplaying all return attributes of type 'MyAttribute'\n"); ICustomAttributeProvider myCustomAttributeProvider = myLogicalMethodInfo.ReturnTypeCustomAttributeProvider; if (myCustomAttributeProvider.IsDefined(typeof(MyAttribute), true)) { attributes = myCustomAttributeProvider.GetCustomAttributes(true); for (int i = 0; i < attributes.Length; i++) { if (attributes[i].GetType().Equals(typeof(MyAttribute))) { Console.WriteLine(((MyAttribute)attributes[i]).Name); } } } // Display all the custom attributes of type 'MyAttribute'. Console.WriteLine("\nDisplaying all attributes of type 'MyAttribute'\n"); myCustomAttributeProvider = myLogicalMethodInfo.CustomAttributeProvider; if (myCustomAttributeProvider.IsDefined(typeof(MyAttribute), true)) { attributes = myCustomAttributeProvider.GetCustomAttributes(true); for (int i = 0; i < attributes.Length; i++) { if (attributes[i].GetType().Equals(typeof(MyAttribute))) { Console.WriteLine(((MyAttribute)attributes[i]).Name); } } } }
public override object GetInitializer ( LogicalMethodInfo methodInfo , SoapExtensionAttribute attribute ) { return(null); }
internal static void IncludeTypes(LogicalMethodInfo[] methods, XmlReflectionImporter importer) { for (int i = 0; i < methods.Length; i++) { LogicalMethodInfo method = methods[i]; IncludeTypes(method, importer); } }
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { if (!(attribute is ValidationAttribute)) { throw new NotSupportedException("Schematron validation must be enabled through the ValidationAttribute."); } return(new ExtensionInitializer(methodInfo.DeclaringType.Assembly, (ValidationAttribute)attribute)); }
internal static void IncludeTypes(LogicalMethodInfo[] methods, XmlReflectionImporter importer) { for (int i = 0; i < methods.Length; i++) { LogicalMethodInfo method = methods[i]; importer.IncludeTypes(method.DeclaringType); importer.IncludeTypes(method.CustomAttributeProvider); } }
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { if (attribute == null) { throw new ArgumentNullException("attribute"); } object ret = attribute; return ret; }
/// <summary> /// When the SOAP extension is accessed for the first time, the XML Web /// service method it is applied to is accessed to store the file /// name passed in, using the corresponding SoapExtensionAttribute. /// </summary> /// <param name="methodInfo">The method being called.</param> /// <param name="attribute">Decorating attribute for the method.</param> /// <returns>An initializer object.</returns> /// <exception cref="ArgumentNullException">Thrown if /// <paramref name="methodInfo"/> is null.</exception> public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { if (methodInfo == null) { throw new ArgumentNullException("methodInfo"); } return(methodInfo.DeclaringType); }
internal static WebMethodAttribute GetAttribute(LogicalMethodInfo method) { object[] attrs = method.GetCustomAttributes(typeof(WebMethodAttribute)); if (attrs.Length == 0) { return(new WebMethodAttribute()); } return((WebMethodAttribute)attrs[0]); }
static string[] GetParameterOrder(LogicalMethodInfo methodInfo) { ParameterInfo[] parameters = methodInfo.Parameters; string[] parameterOrder = new string[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { parameterOrder[i] = parameters[i].Name; } return(parameterOrder); }
private static string[] GetParameterOrder(LogicalMethodInfo methodInfo) { ParameterInfo[] parameters = methodInfo.Parameters; string[] strArray = new string[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { strArray[i] = parameters[i].Name; } return(strArray); }
internal static void IncludeTypes(LogicalMethodInfo method, XmlReflectionImporter importer) { if (method.Declaration != null) { importer.IncludeTypes(method.Declaration.DeclaringType); importer.IncludeTypes(method.Declaration); } importer.IncludeTypes(method.DeclaringType); importer.IncludeTypes(method.CustomAttributeProvider); }
public HttpGetMethodStubInfo(TypeStubInfo parent, LogicalMethodInfo source) : base(parent, source) { ParameterReaderType = new MimeFormatterInfo(typeof(UrlParameterReader)); ReturnWriterType = new MimeFormatterInfo(typeof(XmlReturnWriter)); if (ParameterWriterType == null) { ParameterWriterType = new MimeFormatterInfo(typeof(UrlParameterWriter)); } }
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { YMLAttribute attr = attribute as YMLAttribute; if (attr != null) { return(attr.Disabled); } return(false); }
public void BeginEndMethodInfo() { LogicalMethodInfo [] ll = LogicalMethodInfo.Create( new MethodInfo [] { typeof(FooService).GetMethod("BeginEcho"), typeof(FooService).GetMethod("EndEcho") }); Assert.AreEqual(1, ll.Length, "#1"); LogicalMethodInfo l = ll [0]; Assert.IsNull(l.MethodInfo, "#2"); Assert.IsNotNull(l.BeginMethodInfo, "#3"); Assert.IsNotNull(l.EndMethodInfo, "#4"); }
internal static WebServiceBindingAttribute GetAttribute(LogicalMethodInfo methodInfo, string binding) { Type type = methodInfo.DeclaringType; object[] attrs = type.GetCustomAttributes(typeof(WebServiceBindingAttribute), false); foreach (WebServiceBindingAttribute attr in attrs) { if (attr.Name == binding) { return(attr); } } throw new ArgumentException(Res.GetString(Res.TypeIsMissingWebServiceBindingAttributeThat2, type.FullName, binding), "methodInfo"); }
internal static LogicalMethodInfo[] GetMethods(Type type) { ArrayList list = new ArrayList(); MethodInfo[] methods = type.GetMethods(); for (int i = 0; i < methods.Length; i++) { if (methods[i].GetCustomAttributes(typeof(WebMethodAttribute), false).Length > 0) { list.Add(methods[i]); } } return(LogicalMethodInfo.Create((MethodInfo[])list.ToArray(typeof(MethodInfo)))); }
public static void Main() { Type myType = typeof(MyService); MethodInfo myMethodInfo = myType.GetMethod("MyMethod"); LogicalMethodInfo myLogicalMethodInfo = (LogicalMethodInfo.Create(new MethodInfo[] { myMethodInfo }))[0]; Console.WriteLine("\nPrinting parameters for the method : {0}", myLogicalMethodInfo.Name); Console.WriteLine("\nThe parameters of the method {0} are :\n", myLogicalMethodInfo.Name); ParameterInfo[] myParameters = myLogicalMethodInfo.Parameters; for (int i = 0; i < myParameters.Length; i++) { Console.WriteLine("\t" + myParameters[i].Name + " : " + myParameters[i].ParameterType); } Console.WriteLine("\nThe in parameters of the method {0} are :\n", myLogicalMethodInfo.Name); myParameters = myLogicalMethodInfo.InParameters; for (int i = 0; i < myParameters.Length; i++) { Console.WriteLine("\t" + myParameters[i].Name + " : " + myParameters[i].ParameterType); } Console.WriteLine("\nThe out parameters of the method {0} are :\n", myLogicalMethodInfo.Name); myParameters = myLogicalMethodInfo.OutParameters; for (int i = 0; i < myParameters.Length; i++) { Console.WriteLine("\t" + myParameters[i].Name + " : " + myParameters[i].ParameterType); } if (myLogicalMethodInfo.IsVoid) { Console.WriteLine("\nThe return type is void"); } else { Console.WriteLine("\nThe return type is {0}", myLogicalMethodInfo.ReturnType); } }
/// <summary> /// This method logs soap method calls. /// </summary> /// <param name="Msg"></param> private void Log(SoapMessage Msg) { CallLog = this.LogHeader(Msg) + "("; if (Msg.Stage == SoapMessageStage.AfterDeserialize) { LogicalMethodInfo M = Msg.MethodInfo; int n = 0; foreach (ParameterInfo P in M.InParameters) { CallLog += LogInParameter(P, Msg.GetInParameterValue(n), LogSoapComplexTypes) + ","; n++; } if (CallLog.Substring(CallLog.Length - 1, 1) == ",") { CallLog = CallLog.Substring(0, CallLog.Length - 1); } } CallLog += ")"; }
public static void Main() { Type myType = typeof(MyService); MethodInfo myBeginMethod = myType.GetMethod("BeginAdd"); MethodInfo myEndMethod = myType.GetMethod("EndAdd"); LogicalMethodInfo myLogicalMethodInfo = (LogicalMethodInfo.Create(new MethodInfo[] { myBeginMethod, myEndMethod }, LogicalMethodTypes.Async))[0]; Console.WriteLine("\nThe asynchronous callback parameter of method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.AsyncCallbackParameter.Name + " : " + myLogicalMethodInfo.AsyncCallbackParameter.ParameterType); Console.WriteLine("\nThe asynchronous state parameter of method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.AsyncStateParameter.Name + " : " + myLogicalMethodInfo.AsyncStateParameter.ParameterType); Console.WriteLine("\nThe asynchronous result parameter of method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.AsyncResultParameter.Name + " : " + myLogicalMethodInfo.AsyncResultParameter.ParameterType); Console.WriteLine("\nThe begin method of the asynchronous method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.BeginMethodInfo); Console.WriteLine("\nThe end method of the asynchronous method {0} is :\n", myLogicalMethodInfo.Name); Console.WriteLine("\t" + myLogicalMethodInfo.EndMethodInfo); if (myLogicalMethodInfo.IsAsync) { Console.WriteLine("\n{0} is asynchronous", myLogicalMethodInfo.Name); } else { Console.WriteLine("\n{0} is synchronous", myLogicalMethodInfo.Name); } }
void CheckForDuplicateMethods(LogicalMethodInfo[] methods) { Hashtable messageNames = new Hashtable(); foreach (LogicalMethodInfo method in methods) { WebMethodAttribute attribute = WebMethodReflector.GetAttribute(method); string messageName = attribute.MessageName; if (messageName.Length == 0) { messageName = method.Name; } LogicalMethodInfo existingMethod = (LogicalMethodInfo)messageNames[messageName]; if (existingMethod != null) { throw new InvalidOperationException(Res.GetString(Res.BothAndUseTheMessageNameUseTheMessageName3, method, existingMethod, messageName)); } messageNames.Add(messageName, method); } }
private void CheckForDuplicateMethods(LogicalMethodInfo[] methods) { Hashtable hashtable = new Hashtable(); foreach (LogicalMethodInfo info in methods) { string messageName = info.MethodAttribute.MessageName; if (messageName.Length == 0) { messageName = info.Name; } string key = (info.Binding == null) ? messageName : (info.Binding.Name + "." + messageName); LogicalMethodInfo info2 = (LogicalMethodInfo)hashtable[key]; if (info2 != null) { throw new InvalidOperationException(System.Web.Services.Res.GetString("BothAndUseTheMessageNameUseTheMessageName3", new object[] { info, info2, XmlConvert.EncodeLocalName(messageName) })); } hashtable.Add(key, info); } }
// Methods public abstract virtual object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { }
public static object[] GetInitializers(Type type, LogicalMethodInfo[] methodInfos) {}
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { return CreateAlgorithm (); }
protected override MethodStubInfo CreateMethodStubInfo (TypeStubInfo typeInfo, LogicalMethodInfo methodInfo, bool isClientProxy) { if (isClientProxy && methodInfo.ActualMethodInfo.GetCustomAttributes (typeof(HttpMethodAttribute),true).Length == 0) return null; if (!ValueCollectionParameterReader.IsSupported (methodInfo)) return null; return new HttpGetMethodStubInfo (typeInfo, methodInfo); }
public SoapServerMethod(Type serverType, LogicalMethodInfo methodInfo) { }
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { return false; }
public virtual object GetInitializer(LogicalMethodInfo methodInfo) { }
public virtual object[] GetInitializers(LogicalMethodInfo[] methodInfos) { }
// When the SOAP extension is accessed for the first time, the XML Web // service method it is applied to is accessed to store the file // name passed in, using the corresponding SoapExtensionAttribute. public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { return ((TraceExtensionAttribute) attribute).Filename; }
public static object GetInitializer(Type type, LogicalMethodInfo methodInfo) {}
public static bool IsSupported(LogicalMethodInfo methodInfo) { }