public static void Main() { ServiceDescription myServiceDescription = ServiceDescription.Read("MathService_1.wsdl"); Console.WriteLine(""); Console.WriteLine("MessageCollection Sample"); Console.WriteLine("========================"); Console.WriteLine(""); // <Snippet2> // Get Message Collection. MessageCollection myMessageCollection = myServiceDescription.Messages; Console.WriteLine("Total Messages in the document = " + myServiceDescription.Messages.Count); Console.WriteLine(""); Console.WriteLine("Enumerating Messages..."); Console.WriteLine(""); // Print messages to console. for (int i = 0; i < myMessageCollection.Count; ++i) { Console.WriteLine("Message Name : " + myMessageCollection[i].Name); } // </Snippet2> // <Snippet1> // Create a Message Array. Message[] myMessages = new Message[myServiceDescription.Messages.Count]; // Copy MessageCollection to an array. myServiceDescription.Messages.CopyTo(myMessages, 0); Console.WriteLine(""); Console.WriteLine("Displaying Messages that were copied to Messagearray ..."); Console.WriteLine(""); for (int i = 0; i < myServiceDescription.Messages.Count; ++i) { Console.WriteLine("Message Name : " + myMessages[i].Name); } // </Snippet1> // <Snippet3> // <Snippet4> // <Snippet5> // <Snippet6> // Get Message by Name = "AddSoapIn". Message myMessage = myServiceDescription.Messages["AddSoapIn"]; Console.WriteLine(""); Console.WriteLine("Getting Message = 'AddSoapIn' {by Name}"); if (myMessageCollection.Contains(myMessage)) { Console.WriteLine(""); // Get Message Name = "AddSoapIn" Index. Console.WriteLine("Message 'AddSoapIn' was found in Message Collection."); Console.WriteLine("Index of 'AddSoapIn' in Message Collection = " + myMessageCollection.IndexOf(myMessage)); Console.WriteLine("Deleting Message from Message Collection..."); myMessageCollection.Remove(myMessage); if (myMessageCollection.IndexOf(myMessage) == -1) { Console.WriteLine("Message 'AddSoapIn' was successfully removed from Message Collection."); } } // </Snippet6> // </Snippet5> // </Snippet4> // </Snippet3> }
public static void Main() { Console.WriteLine(""); Console.WriteLine("MessagePartCollection Sample"); Console.WriteLine("============================"); Console.WriteLine(""); ServiceDescription myServiceDescription = ServiceDescription.Read("MathService.wsdl"); // Get the message collection. MessageCollection myMessageCollection = myServiceDescription.Messages; Console.WriteLine("Total Messages in the document = " + myServiceDescription.Messages.Count); Console.WriteLine(""); Console.WriteLine("Enumerating PartCollection for each message..."); Console.WriteLine(""); // Get the message part collection for each message. for (int i = 0; i < myMessageCollection.Count; ++i) { Console.WriteLine("Message : " + myMessageCollection[i].Name); // Get the message part collection. MessagePartCollection myMessagePartCollection = myMessageCollection[i].Parts; // Display the part collection. for (int k = 0; k < myMessagePartCollection.Count; k++) { Console.WriteLine("\t Part Name : " + myMessagePartCollection[k].Name); Console.WriteLine("\t Message Name : " + myMessagePartCollection[k].Message.Name); } Console.WriteLine(""); } Console.WriteLine("Displaying the array copied from the " + "MessagePartCollection for the message AddHttpGetIn."); Message myLocalMessage = myServiceDescription.Messages["AddHttpPostOut"]; if (myMessageCollection.Contains(myLocalMessage)) { Console.WriteLine("Message : " + myLocalMessage.Name); // Get the message part collection. MessagePartCollection myMessagePartCollection = myLocalMessage.Parts; MessagePart[] myMessagePart = new MessagePart[myMessagePartCollection.Count]; // Copy the MessagePartCollection to an array. myMessagePartCollection.CopyTo(myMessagePart, 0); for (int k = 0; k < myMessagePart.Length; k++) { Console.WriteLine("\t Part Name : " + myMessagePartCollection[k].Name); } Console.WriteLine(""); } Console.WriteLine("Checking if message is AddHttpPostOut..."); Message myMessage = myServiceDescription.Messages["AddHttpPostOut"]; if (myMessageCollection.Contains(myMessage)) { // Get the message part collection. MessagePartCollection myMessagePartCollection = myMessage.Parts; // Get the part named Body. MessagePart myMessagePart = myMessage.Parts["Body"]; if (myMessagePartCollection.Contains(myMessagePart)) { // Get the index of the part named Body. Console.WriteLine("Index of Body in MessagePart collection = " + myMessagePartCollection.IndexOf(myMessagePart)); Console.WriteLine("Deleting Body from MessagePart collection..."); myMessagePartCollection.Remove(myMessagePart); if (myMessagePartCollection.IndexOf(myMessagePart) == -1) { Console.WriteLine("MessagePart Body successfully deleted " + "from the message AddHttpPostOut."); } } } }