public void InitializeOperation()
        {
            // workaround for internal constructor
            Operation op = new Operation();

            operations = op.Messages;
        }
Exemple #2
0
        public List <WSOperation> GetOperations()
        {
            List <WSOperation> lst = new List <WSOperation>();

            if (serviceDescription != null)
            {
                foreach (Service ser in serviceDescription.Services)
                {
                    String webServiceName = ser.Name.ToString();
                    foreach (Port port in ser.Ports)
                    {
                        string  portName = port.Name;
                        string  binding  = port.Binding.Name;
                        Binding bind     = bindColl[binding];

                        if (bind != null)
                        {
                            PortType portTyp = portTypColl[bind.Type.Name];

                            foreach (Operation op in portTyp.Operations)
                            {
                                WSOperation operObj = new WSOperation();
                                operObj.ClassName  = webServiceName;
                                operObj.MethodName = op.Name;

                                if (lst.Where(it => it.ClassName.Equals(operObj.ClassName) && it.MethodName.Equals(operObj.MethodName)).Count() == 0)
                                {
                                    OperationMessageCollection opMsgColl = op.Messages;
                                    OperationInput             opInput   = opMsgColl.Input;
                                    OperationOutput            opOutput  = opMsgColl.Output;
                                    string inputMsg  = opInput.Message.Name;
                                    string outputMsg = opOutput.Message.Name;

                                    Message            msgInput   = msgColl[inputMsg];
                                    List <WSParameter> InputParam = GetParameters(msgInput);

                                    Message            msgOutput    = msgColl[outputMsg];
                                    List <WSParameter> OutputParams = GetParameters(msgOutput);

                                    operObj.Parameters = InputParam;
                                    if (OutputParams != null && OutputParams.Count > 0)
                                    {
                                        operObj.ReturnType = OutputParams[0].TypeName;
                                    }

                                    lst.Add(operObj);
                                }
                            }
                        }
                    }
                }
            }
            return(lst);
        }
// <Snippet9>
// <Snippet10>
// <Snippet11>
    // Displays the properties of the OperationMessageCollection.
    public static void DisplayFlowInputOutput(OperationMessageCollection
                                              myOperationMessageCollection, string myOperation)
    {
        Console.WriteLine("After " + myOperation + ":");
        Console.WriteLine("Flow : " + myOperationMessageCollection.Flow);
        Console.WriteLine("The first occurrence of operation Input " +
                          "in the collection " + myOperationMessageCollection.Input);
        Console.WriteLine("The first occurrence of operation Output " +
                          "in the collection " + myOperationMessageCollection.Output);
        Console.WriteLine();
    }
Exemple #4
0
        private OperationMessage FindOperationMessageByName(OperationMessageCollection operationMessages, string wrapperName, string wrapperNamespace)
        {
            foreach (OperationMessage operationMessage in operationMessages)
            {
                var message = operationMessage.Message;
                if (message.Name == wrapperName && message.Namespace == wrapperNamespace)
                {
                    return(operationMessage);
                }
            }

            return(null);
        }
        private static string GetMessages(OperationMessageCollection messages)
        {
            StringBuilder logMessages = new StringBuilder();

            foreach (var message in messages)
            {
                string logMessage = String.Format(@"Message id: {0}. {1} - Type: {2}: {3}"
                                                  , message.Id
                                                  , message.MessageTime
                                                  , GetMessageType(message.MessageType)
                                                  , message.Message);
                logMessages.AppendLine(logMessage);
            }

            return(logMessages.ToString());
        }
    static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("MathService_input_cs.wsdl");
            PortTypeCollection myPortTypeCollection =
                myDescription.PortTypes;

            // Get the OperationCollection for the SOAP protocol.
            OperationCollection myOperationCollection =
                myPortTypeCollection[0].Operations;

            // Get the OperationMessageCollection for the Add operation.
            OperationMessageCollection myOperationMessageCollection =
                myOperationCollection[0].Messages;

// <Snippet2>
// <Snippet4>
// <Snippet3>
            OperationMessage myInputOperationMessage =
                (OperationMessage) new OperationInput();
            XmlQualifiedName myXmlQualifiedName = new XmlQualifiedName(
                "AddSoapIn", myDescription.TargetNamespace);
            myInputOperationMessage.Message = myXmlQualifiedName;
// </Snippet3>
            myOperationMessageCollection.Insert(0, myInputOperationMessage);

            // Display the operation name of the InputMessage.
            Console.WriteLine("The operation name is " +
                              myInputOperationMessage.Operation.Name);

// </Snippet4>
// </Snippet2>
            // Add the OperationMessage to the collection.
            myDescription.Write("MathService_new_cs.wsdl");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
Exemple #7
0
    public static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("MathService_Input_cs.wsdl");
            PortTypeCollection myPortTypeCollection =
                myDescription.PortTypes;

            // Get the OperationCollection for SOAP protocol.
            OperationCollection myOperationCollection =
                myPortTypeCollection[0].Operations;

            // Get the OperationMessageCollection for the Add operation.
            OperationMessageCollection myOperationMessageCollection =
                myOperationCollection[0].Messages;

            // Indicate that the endpoint or service receives no
            // transmissions (None).
            Console.WriteLine("myOperationMessageCollection does not " +
                              "contain any operation messages.");
            DisplayOperationFlowDescription(myOperationMessageCollection.Flow);
            Console.WriteLine();

            // Indicate that the endpoint or service receives a message (OneWay).
            OperationMessage myInputOperationMessage =
                (OperationMessage) new OperationInput();
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("AddSoapIn", myDescription.TargetNamespace);
            myInputOperationMessage.Message = myXmlQualifiedName;
            myOperationMessageCollection.Add(myInputOperationMessage);
            Console.WriteLine("myOperationMessageCollection contains " +
                              "only input operation messages.");
            DisplayOperationFlowDescription(myOperationMessageCollection.Flow);
            Console.WriteLine();

            myOperationMessageCollection.Remove(myInputOperationMessage);

            // Indicate that an endpoint or service sends a message (Notification).
            OperationMessage myOutputOperationMessage =
                (OperationMessage) new OperationOutput();
            XmlQualifiedName myXmlQualifiedName1 = new XmlQualifiedName
                                                       ("AddSoapOut", myDescription.TargetNamespace);
            myOutputOperationMessage.Message = myXmlQualifiedName1;
            myOperationMessageCollection.Add(myOutputOperationMessage);
            Console.WriteLine("myOperationMessageCollection contains " +
                              "only output operation messages.");
            DisplayOperationFlowDescription(myOperationMessageCollection.Flow);
            Console.WriteLine();

            // Indicate that an endpoint or service sends a message, then
            // receives a correlated message (SolicitResponse).
            myOperationMessageCollection.Add(myInputOperationMessage);
            Console.WriteLine("'myOperationMessageCollection' contains " +
                              "an output operation message first, then " +
                              "an input operation message.");
            DisplayOperationFlowDescription(myOperationMessageCollection.Flow);
            Console.WriteLine();

            // Indicate that an endpoint or service receives a message,
            // then sends a correlated message (RequestResponse).
            myOperationMessageCollection.Remove(myInputOperationMessage);
            myOperationMessageCollection.Insert(0, myInputOperationMessage);
            Console.WriteLine("myOperationMessageCollection contains " +
                              "an input operation message first, then " +
                              "an output operation message.");
            DisplayOperationFlowDescription(myOperationMessageCollection.Flow);
            Console.WriteLine();

            myDescription.Write("MathService_new_cs.wsdl");
            Console.WriteLine(
                "The file MathService_new_cs.wsdl was successfully written.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
    static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("MathService_input_cs.wsdl");
            PortTypeCollection myPortTypeCollection =
                myDescription.PortTypes;

            // Get the OperationCollection for the SOAP protocol.
            OperationCollection myOperationCollection =
                myPortTypeCollection[0].Operations;

            // Get the OperationMessageCollection for the Add operation.
            OperationMessageCollection myOperationMessageCollection =
                myOperationCollection[0].Messages;

            // Display the Flow, Input, and Output properties.
            DisplayFlowInputOutput(myOperationMessageCollection, "Start");

// <Snippet2>
// <Snippet4>
            // Get the operation message for the Add operation.
            OperationMessage myOperationMessage =
                myOperationMessageCollection[0];
            OperationMessage myInputOperationMessage =
                (OperationMessage) new OperationInput();
            XmlQualifiedName myXmlQualifiedName = new XmlQualifiedName(
                "AddSoapIn", myDescription.TargetNamespace);
            myInputOperationMessage.Message = myXmlQualifiedName;

// <Snippet3>
            OperationMessage[] myCollection =
                new OperationMessage[myOperationMessageCollection.Count];
            myOperationMessageCollection.CopyTo(myCollection, 0);
            Console.WriteLine("Operation name(s) :");
            for (int i = 0; i < myCollection.Length; i++)
            {
                Console.WriteLine(" " + myCollection[i].Operation.Name);
            }

// </Snippet3>
            // Add the OperationMessage to the collection.
            myOperationMessageCollection.Add(myInputOperationMessage);
// </Snippet4>
            DisplayFlowInputOutput(myOperationMessageCollection, "Add");

// <Snippet5>
// <Snippet6>
            if (myOperationMessageCollection.Contains(myOperationMessage)
                == true)
            {
                int myIndex =
                    myOperationMessageCollection.IndexOf(myOperationMessage);
                Console.WriteLine(" The index of the Add operation " +
                                  "message in the collection is : " + myIndex);
            }
// </Snippet6>
// </Snippet5>
// </Snippet2>

// <Snippet7>
// <Snippet8>
            myOperationMessageCollection.Remove(myInputOperationMessage);

            // Display Flow, Input, and Output after removing.
            DisplayFlowInputOutput(myOperationMessageCollection, "Remove");

            // Insert the message at index 0 in the collection.
            myOperationMessageCollection.Insert(0, myInputOperationMessage);

            // Display Flow, Input, and Output after inserting.
            DisplayFlowInputOutput(myOperationMessageCollection, "Insert");
// </Snippet8>
// </Snippet7>

            myDescription.Write("MathService_new_cs.wsdl");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
Exemple #9
0
    public static void Main()
    {
        ServiceDescription myServiceDescription = new ServiceDescription();

        myServiceDescription.Name            = "StockQuote";
        myServiceDescription.TargetNamespace = "http://www.contoso.com/stockquote.wsdl";

        // Generate the 'Types' element.
        XmlSchema myXmlSchema = new XmlSchema();

        myXmlSchema.AttributeFormDefault = XmlSchemaForm.Qualified;
        myXmlSchema.ElementFormDefault   = XmlSchemaForm.Qualified;
        myXmlSchema.TargetNamespace      = "http://www.contoso.com/stockquote.wsdl";

        //XmlSchemaElement myXmlSchemaElement;
        XmlSchemaComplexType myXmlSchemaComplexType = new XmlSchemaComplexType();

        myXmlSchemaComplexType.Name = "GetTradePriceInputType";
        XmlSchemaSequence myXmlSchemaSequence = new XmlSchemaSequence();

        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "tickerSymbol", true, new XmlQualifiedName("s:string")));
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "time", true, new XmlQualifiedName("s:string")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchemaComplexType      = new XmlSchemaComplexType();
        myXmlSchemaComplexType.Name = "GetTradePriceOutputType";
        myXmlSchemaSequence         = new XmlSchemaSequence();
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "result", true, new XmlQualifiedName("s:string")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchemaComplexType      = new XmlSchemaComplexType();
        myXmlSchemaComplexType.Name = "GetTradePriceStringFaultType";
        myXmlSchemaSequence         = new XmlSchemaSequence();
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "error", true, new XmlQualifiedName("s:string")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchemaComplexType      = new XmlSchemaComplexType();
        myXmlSchemaComplexType.Name = "GetTradePriceStringIntType";
        myXmlSchemaSequence         = new XmlSchemaSequence();
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "error", true, new XmlQualifiedName("s:int")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapIn", new XmlQualifiedName("s0:GetTradePriceInputType")));
        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapOut", new XmlQualifiedName("s0:GetTradePriceOutputType")));
        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapStringFault", new XmlQualifiedName("s0:GetTradePriceStringFaultType")));
        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapIntFault", new XmlQualifiedName("s0:GetTradePriceIntFaultType")));

        myServiceDescription.Types.Schemas.Add(myXmlSchema);

        // Generate the 'Message' element.
        MessageCollection myMessageCollection = myServiceDescription.Messages;

        myMessageCollection.Add(CreateMessage("GetTradePriceInput", "parameters", "GetTradePriceSoapIn", myServiceDescription.TargetNamespace));
        myMessageCollection.Add(CreateMessage("GetTradePriceOutput", "parameters", "GetTradePriceSoapOut", myServiceDescription.TargetNamespace));
        myMessageCollection.Add(CreateMessage("GetTradePriceStringFault", "parameters", "GetTradePriceStringSoapFault", myServiceDescription.TargetNamespace));
        myMessageCollection.Add(CreateMessage("GetTradePriceIntFault", "parameters", "GetTradePriceIntSoapFault", myServiceDescription.TargetNamespace));

        // Generate the 'Port Type' element.
        PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes;
        PortType           myPortType           = new PortType();

        myPortType.Name = "StockQuotePortType";
        OperationCollection myOperationCollection = myPortType.Operations;
        Operation           myOperation           = new Operation();

        myOperation.Name = "GetTradePrice";
        OperationMessage           myOperationMessage;
        OperationMessageCollection myOperationMessageCollection = myOperation.Messages;

        myOperationMessage         = (OperationMessage) new OperationInput();
        myOperationMessage.Message = new XmlQualifiedName("s0:GetTradePriceInput");
        myOperationMessageCollection.Add(myOperationMessage);
        myOperationMessage         = (OperationMessage) new OperationOutput();
        myOperationMessage.Message = new XmlQualifiedName("s0:GetTradePriceOutput");
        myOperationMessageCollection.Add(myOperationMessage);
        OperationFault myOperationFault = new OperationFault();

        myOperationFault.Name    = "ErrorString";
        myOperationFault.Message = new XmlQualifiedName("s0:GetTradePriceStringFault");
        myOperation.Faults.Add(myOperationFault);
        myOperationFault         = new OperationFault();
        myOperationFault.Name    = "ErrorInt";
        myOperationFault.Message = new XmlQualifiedName("s0:GetTradePriceIntFault");
        myOperation.Faults.Add(myOperationFault);
        myOperationCollection.Add(myOperation);
        myPortTypeCollection.Add(myPortType);

        // Generate the 'Binding' element.
        ServiceDescriptionFormatExtensionCollection myExtensions;
        BindingCollection myBindingCollection = myServiceDescription.Bindings;
        Binding           myBinding           = new Binding();

        myBinding.Name = "StockQuoteSoapBinding";
        myBinding.Type = new XmlQualifiedName("s0:StockQuotePortType");
        myExtensions   = myBinding.Extensions;
        SoapBinding mySoapBinding = new SoapBinding();

        mySoapBinding.Style     = SoapBindingStyle.Document;
        mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";
        myExtensions.Add(mySoapBinding);
        OperationBindingCollection myOperationBindingCollection = myBinding.Operations;
        OperationBinding           myOperationBinding           = new OperationBinding();

        myExtensions = myOperationBinding.Extensions;
        SoapOperationBinding mySoapBindingOperation = new SoapOperationBinding();

        mySoapBindingOperation.SoapAction = "http://www.contoso.com/GetTradePrice";
        myExtensions.Add(mySoapBindingOperation);
        myOperationBinding.Name  = "GetTradePrice";
        myOperationBinding.Input = new InputBinding();
        myExtensions             = myOperationBinding.Input.Extensions;
        SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();

        mySoapBodyBinding.Use       = SoapBindingUse.Literal;
        mySoapBodyBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapBodyBinding);
        myOperationBinding.Output = new OutputBinding();
        myExtensions                = myOperationBinding.Output.Extensions;
        mySoapBodyBinding           = new SoapBodyBinding();
        mySoapBodyBinding.Use       = SoapBindingUse.Literal;
        mySoapBodyBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapBodyBinding);
// <Snippet1>
// <Snippet2>
// <Snippet3>
        FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults;
        FaultBinding           myFaultBinding           = new FaultBinding();

        myFaultBinding.Name = "ErrorString";
        // Associate SOAP fault binding to the fault binding of the operation.
        myExtensions = myFaultBinding.Extensions;
        SoapFaultBinding mySoapFaultBinding = new SoapFaultBinding();

        mySoapFaultBinding.Use       = SoapBindingUse.Literal;
        mySoapFaultBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapFaultBinding);
        myFaultBindingCollection.Add(myFaultBinding);
// </Snippet3>
// </Snippet2>
// </Snippet1>
        myFaultBinding      = new FaultBinding();
        myFaultBinding.Name = "ErrorInt";
        // Associate SOAP fault binding to the fault binding of the operation.
        myExtensions                 = myFaultBinding.Extensions;
        mySoapFaultBinding           = new SoapFaultBinding();
        mySoapFaultBinding.Use       = SoapBindingUse.Literal;
        mySoapFaultBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapFaultBinding);
        myFaultBindingCollection.Add(myFaultBinding);
        myOperationBindingCollection.Add(myOperationBinding);
        myBindingCollection.Add(myBinding);

        // Generate the 'Service' element.
        ServiceCollection myServiceCollection = myServiceDescription.Services;
// <Snippet4>
        Service myService = new Service();

        // Add a simple documentation for the service to ease the readability of the generated WSDL file.
        myService.Documentation = "A Simple Stock Quote Service";
        myService.Name          = "StockQuoteService";
        PortCollection myPortCollection = myService.Ports;
        Port           myPort           = new Port();

        myPort.Name    = "StockQuotePort";
        myPort.Binding = new XmlQualifiedName("s0:StockQuoteSoapBinding");
        myExtensions   = myPort.Extensions;
        SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();

        mySoapAddressBinding.Location = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapAddressBinding);
        myPortCollection.Add(myPort);
// </Snippet4>
        myServiceCollection.Add(myService);

        // Display the WSDL generated to the console.
        myServiceDescription.Write(Console.Out);
    }