Exemple #1
0
	public void Parse()
	{			
	foreach (Service service in _services[0].Services )
	{
	TreeNode tnService=new TreeNode(service.Name) ;
	tnService.ImageIndex=1;
	tnService.SelectedImageIndex=1;

	foreach (Port port in service.Ports)
	{
	XmlQualifiedName bindName=port.Binding ;
	Binding bind=_services.GetBinding(bindName);			
	PortType portType=_services.GetPortType(bind.Type) ;
       TreeNode tnPort=new TreeNode (port.Name);
	tnPort.ImageIndex=6;
	tnPort.SelectedImageIndex=6;
	string protocol=GetProtocol (bind);
	string portDesc="Protocol: " + protocol + "\n";
      	switch (protocol) 
	{
	case "Soap":
	{
	SoapAddressBinding ad=(SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
	portDesc += "Location: " + ad.Location + "\n";
	break;
	 }
	 case "HttpGet":
	{
	HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
	portDesc += "Location: " + ad.Location + "\n";
break;
	case "HttpPost":
	{
	HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
portDesc += "Location: "   + ad.Location + "\n";
break;
}
}
tnPort.Tag=portDesc;
foreach (OperationBinding obin in bind.Operations)					
{									
foreach (Operation oper in portType.Operations)
if (obin.Name.Equals(oper.Name) )
{
TreeNode tnOper=TranslateOperation (port, obin, oper, protocol);										
tnOper.ImageIndex=11;
tnOper.SelectedImageIndex=11;
if (tnOper != null)
{
tnPort.Nodes.Add (tnOper);	};
}												
}
tnPort.Expand ();					
tnService.Nodes.Add(tnPort) ;
}
ServiceNode.Nodes.Add (tnService);					
}
}		
Exemple #2
0
        public string GenerateHttpGetMessage(Port port, OperationBinding obin, Operation oper, OperationMessage msg)
        {
            string req = "";

            if (msg is OperationInput)
            {
                HttpAddressBinding   sab = port.Extensions.Find(typeof(HttpAddressBinding)) as HttpAddressBinding;
                HttpOperationBinding sob = obin.Extensions.Find(typeof(HttpOperationBinding)) as HttpOperationBinding;
                string location          = new Uri(sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString(msg);
                req += "GET " + location + "\n";
                req += "Host: " + GetLiteral("string");
            }
            else
            {
                req += "HTTP/1.0 200 OK\n";
                req += "Content-Type: text/xml; charset=utf-8\n";
                req += "Content-Length: " + GetLiteral("string") + "\n\n";

                MimeXmlBinding mxb = (MimeXmlBinding)obin.Output.Extensions.Find(typeof(MimeXmlBinding)) as MimeXmlBinding;
                if (mxb == null)
                {
                    return(req);
                }

                Message          message = descriptions.GetMessage(msg.Message);
                XmlQualifiedName ename   = null;
                foreach (MessagePart part in message.Parts)
                {
                    if (part.Name == mxb.Part)
                    {
                        ename = part.Element;
                    }
                }

                if (ename == null)
                {
                    return(req + GetLiteral("string"));
                }

                StringWriter  sw  = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(sw);
                xtw.Formatting = Formatting.Indented;
                currentUse     = SoapBindingUse.Literal;
                WriteRootElementSample(xtw, ename);
                xtw.Close();
                req += sw.ToString();
            }

            return(req);
        }
Exemple #3
0
        public string GenerateHttpPostMessage(Port port, OperationBinding obin, Operation oper, OperationMessage msg)
        {
            string req = "";

            if (msg is OperationInput)
            {
                HttpAddressBinding   sab = port.Extensions.Find(typeof(HttpAddressBinding)) as HttpAddressBinding;
                HttpOperationBinding sob = obin.Extensions.Find(typeof(HttpOperationBinding)) as HttpOperationBinding;
                string location          = new Uri(sab.Location).AbsolutePath + sob.Location;
                req += "POST " + location + "\n";
                req += "Content-Type: application/x-www-form-urlencoded\n";
                req += "Content-Length: " + GetLiteral("string") + "\n";
                req += "Host: " + GetLiteral("string") + "\n\n";
                req += BuildQueryString(msg);
            }
            else
            {
                return(GenerateHttpGetMessage(port, obin, oper, msg));
            }

            return(req);
        }
Exemple #4
0
    public static void Main()
    {
        ServiceDescription myDescription = ServiceDescription.Read("AddNumbers1.wsdl");

        // Create the 'Binding' object.
        Binding myBinding = new Binding();

        myBinding.Name = "Service1HttpPost";
        XmlQualifiedName qualifiedName = new XmlQualifiedName("s0:Service1HttpPost");

        myBinding.Type = qualifiedName;

// <Snippet1>
// <Snippet2>

        // Create the 'HttpBinding' object.
        HttpBinding myHttpBinding = new HttpBinding();

        myHttpBinding.Verb = "POST";
        // Add the 'HttpBinding' to the 'Binding'.
        myBinding.Extensions.Add(myHttpBinding);
// </Snippet2>
// </Snippet1>

        // Create the 'OperationBinding' object.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "AddNumbers";

        HttpOperationBinding myOperation = new HttpOperationBinding();

        myOperation.Location = "/AddNumbers";
        // Add the 'HttpOperationBinding' to 'OperationBinding'.
        myOperationBinding.Extensions.Add(myOperation);

        // Create the 'InputBinding' object.
        InputBinding       myInput = new InputBinding();
        MimeContentBinding postMimeContentbinding = new MimeContentBinding();

        postMimeContentbinding.Type = "application/x-www-form-urlencoded";
        myInput.Extensions.Add(postMimeContentbinding);
        // Add the 'InputBinding' to 'OperationBinding'.
        myOperationBinding.Input = myInput;
        // Create the 'OutputBinding' object.
        OutputBinding  myOutput           = new OutputBinding();
        MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();

        postMimeXmlbinding.Part = "Body";
        myOutput.Extensions.Add(postMimeXmlbinding);

        // Add the 'OutPutBinding' to 'OperationBinding'.
        myOperationBinding.Output = myOutput;

        // Add the 'OperationBinding' to 'Binding'.
        myBinding.Operations.Add(myOperationBinding);

        // Add the 'Binding' to 'BindingCollection' of 'ServiceDescription'.
        myDescription.Bindings.Add(myBinding);

        // Create  a 'Port' object.
        Port postPort = new Port();

        postPort.Name    = "Service1HttpPost";
        postPort.Binding = new XmlQualifiedName("s0:Service1HttpPost");

// <Snippet3>
// <Snippet4>

        // Create the 'HttpAddressBinding' object.
        HttpAddressBinding postAddressBinding = new HttpAddressBinding();

        postAddressBinding.Location = "http://localhost/Service1.asmx";

        // Add the 'HttpAddressBinding' to the 'Port'.
        postPort.Extensions.Add(postAddressBinding);
// </Snippet4>
// </Snippet3>

        // Add the 'Port' to 'PortCollection' of 'ServiceDescription'.
        myDescription.Services[0].Ports.Add(postPort);

        // Create a 'PortType' object.
        PortType postPortType = new PortType();

        postPortType.Name = "Service1HttpPost";

        Operation postOperation = new Operation();

        postOperation.Name = "AddNumbers";

        OperationMessage postInput = (OperationMessage) new OperationInput();

        postInput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostIn");
        OperationMessage postOutput = (OperationMessage) new OperationOutput();

        postOutput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostOut");

        postOperation.Messages.Add(postInput);
        postOperation.Messages.Add(postOutput);

        // Add the 'Operation' to 'PortType'.
        postPortType.Operations.Add(postOperation);

        // Adds the 'PortType' to 'PortTypeCollection' of 'ServiceDescription'.
        myDescription.PortTypes.Add(postPortType);

        // Create the 'Message' object.
        Message postMessage1 = new Message();

        postMessage1.Name = "AddNumbersHttpPostIn";
        // Create the 'MessageParts'.
        MessagePart postMessagePart1 = new MessagePart();

        postMessagePart1.Name = "firstnumber";
        postMessagePart1.Type = new XmlQualifiedName("s:string");

        MessagePart postMessagePart2 = new MessagePart();

        postMessagePart2.Name = "secondnumber";
        postMessagePart2.Type = new XmlQualifiedName("s:string");
        // Add the 'MessagePart' objects to 'Messages'.
        postMessage1.Parts.Add(postMessagePart1);
        postMessage1.Parts.Add(postMessagePart2);

        // Create another 'Message' object.
        Message postMessage2 = new Message();

        postMessage2.Name = "AddNumbersHttpPostOut";

        MessagePart postMessagePart3 = new MessagePart();

        postMessagePart3.Name    = "Body";
        postMessagePart3.Element = new XmlQualifiedName("s0:int");
        // Add the 'MessagePart' to 'Message'
        postMessage2.Parts.Add(postMessagePart3);

        // Add the 'Message' objects to 'ServiceDescription'.
        myDescription.Messages.Add(postMessage1);
        myDescription.Messages.Add(postMessage2);

        // Write the 'ServiceDescription' as a WSDL file.
        myDescription.Write("AddNumbers.wsdl");
        Console.WriteLine("WSDL file with name 'AddNumber.Wsdl' file created Successfully");
    }
    public static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("AddNumbersIn_cs.wsdl");

            // Add the ServiceHttpPost binding.
            Binding myBinding = new Binding();
            myBinding.Name = "ServiceHttpPost";
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:ServiceHttpPost");
            myBinding.Type = myXmlQualifiedName;
            HttpBinding myHttpBinding = new HttpBinding();
            myHttpBinding.Verb = "POST";
            myBinding.Extensions.Add(myHttpBinding);

            // Add the operation name AddNumbers.
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "AddNumbers";
            HttpOperationBinding myOperation = new HttpOperationBinding();
            myOperation.Location = "/AddNumbers";
            myOperationBinding.Extensions.Add(myOperation);

            // Add the input binding.
            InputBinding       myInput = new InputBinding();
            MimeContentBinding postMimeContentbinding =
                new MimeContentBinding();
            postMimeContentbinding.Type = "application/x-www-form-urlencoded";
            myInput.Extensions.Add(postMimeContentbinding);

            // Add the InputBinding to the OperationBinding.
            myOperationBinding.Input = myInput;

            // Add the ouput binding.
            OutputBinding  myOutput           = new OutputBinding();
            MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();
            postMimeXmlbinding.Part = "Body";
            myOutput.Extensions.Add(postMimeXmlbinding);

            // Add the OutPutBinding to the OperationBinding.
            myOperationBinding.Output = myOutput;

            myBinding.Operations.Add(myOperationBinding);
            myDescription.Bindings.Add(myBinding);

            // Add the port definition.
            Port postPort = new Port();
            postPort.Name    = "ServiceHttpPost";
            postPort.Binding = new XmlQualifiedName("s0:ServiceHttpPost");
            HttpAddressBinding postAddressBinding = new HttpAddressBinding();
            postAddressBinding.Location = "http://localhost/Service_cs.asmx";
            postPort.Extensions.Add(postAddressBinding);
            myDescription.Services[0].Ports.Add(postPort);

            // Add the post port type definition.
            PortType postPortType = new PortType();
            postPortType.Name = "ServiceHttpPost";
            Operation postOperation = new Operation();
            postOperation.Name = "AddNumbers";
            OperationMessage postInput =
                (OperationMessage) new OperationInput();
            postInput.Message =
                new XmlQualifiedName("s0:AddNumbersHttpPostIn");
// <Snippet2>
            OperationOutput postOutput = new OperationOutput();
            postOutput.Message =
                new XmlQualifiedName("s0:AddNumbersHttpPostOut");

            postOperation.Messages.Add(postInput);
            postOperation.Messages.Add(postOutput);
            postPortType.Operations.Add(postOperation);
// </Snippet2>
            myDescription.PortTypes.Add(postPortType);

            // Add the first message information.
            Message postMessage1 = new Message();
            postMessage1.Name = "AddNumbersHttpPostIn";
            MessagePart postMessagePart1 = new MessagePart();
            postMessagePart1.Name = "firstnumber";
            postMessagePart1.Type = new XmlQualifiedName("s:string");

            // Add the second message information.
            MessagePart postMessagePart2 = new MessagePart();
            postMessagePart2.Name = "secondnumber";
            postMessagePart2.Type = new XmlQualifiedName("s:string");
            postMessage1.Parts.Add(postMessagePart1);
            postMessage1.Parts.Add(postMessagePart2);
            Message postMessage2 = new Message();
            postMessage2.Name = "AddNumbersHttpPostOut";

            // Add the third message information.
            MessagePart postMessagePart3 = new MessagePart();
            postMessagePart3.Name    = "Body";
            postMessagePart3.Element = new XmlQualifiedName("s0:int");
            postMessage2.Parts.Add(postMessagePart3);

            myDescription.Messages.Add(postMessage1);
            myDescription.Messages.Add(postMessage2);

            // Write the ServiceDescription as a WSDL file.
            myDescription.Write("AddNumbersOut_cs.wsdl");
            Console.WriteLine("WSDL file named AddNumbersOut_cs.Wsdl" +
                              " created successfully.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
    public static void Main()
    {
// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
// <Snippet5>
        // Read a ServiceDescription from existing WSDL.
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("Input_CS.wsdl");

        myServiceDescription.TargetNamespace = "http://tempuri.org/";
// </Snippet5>

        // Get the ServiceCollection of the ServiceDescription.
        ServiceCollection myServiceCollection = myServiceDescription.Services;

        // Remove the Service at index 0 of the collection.
        myServiceCollection.Remove(myServiceDescription.Services[0]);
// </Snippet4>
// </Snippet3>
// </Snippet2>

// <Snippet6>
        // Build a new Service.
        Service myService = new Service();

        myService.Name = "MathService";
        XmlQualifiedName myXmlQualifiedName =
            new XmlQualifiedName("s0:MathServiceSoap");

        // Build a new Port for SOAP.
        Port mySoapPort = new Port();

        mySoapPort.Name = "MathServiceSoap";

        mySoapPort.Binding = myXmlQualifiedName;

        SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();

        mySoapAddressBinding.Location =
            "http://localhost/ServiceCollection_Item/AddSub_CS.asmx";
        mySoapPort.Extensions.Add(mySoapAddressBinding);

        // Build a new Port for HTTP-GET.
        XmlQualifiedName myXmlQualifiedName2 =
            new XmlQualifiedName("s0:MathServiceHttpGet");

        Port myHttpGetPort = new Port();

        myHttpGetPort.Name    = "MathServiceHttpGet";
        myHttpGetPort.Binding = myXmlQualifiedName2;
        HttpAddressBinding myHttpAddressBinding = new HttpAddressBinding();

        myHttpAddressBinding.Location =
            "http://localhost/ServiceCollection_Item/AddSub_CS.asmx";
        myHttpGetPort.Extensions.Add(myHttpAddressBinding);

        // Add the ports to the service.
        myService.Ports.Add(myHttpGetPort);
        myService.Ports.Add(mySoapPort);

        // Add the service to the ServiceCollection.
        myServiceCollection.Add(myService);
// </Snippet6>

        // Write to a new WSDL file.
        myServiceDescription.Write("output.wsdl");
// </Snippet1>
    }
Exemple #7
0
    public static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("Operation_2_Input_CS.wsdl");
            Binding myBinding = new Binding();
            myBinding.Name = "Operation_2_ServiceHttpPost";
            XmlQualifiedName myQualifiedName =
                new XmlQualifiedName("s0:Operation_2_ServiceHttpPost");
            myBinding.Type = myQualifiedName;
            HttpBinding myHttpBinding = new HttpBinding();
            myHttpBinding.Verb = "POST";
            // Add the 'HttpBinding' to the 'Binding'.
            myBinding.Extensions.Add(myHttpBinding);
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "AddNumbers";
            HttpOperationBinding myHttpOperationBinding = new HttpOperationBinding();
            myHttpOperationBinding.Location = "/AddNumbers";
            // Add the 'HttpOperationBinding' to 'OperationBinding'.
            myOperationBinding.Extensions.Add(myHttpOperationBinding);
            InputBinding       myInputBinding           = new InputBinding();
            MimeContentBinding myPostMimeContentbinding = new MimeContentBinding();
            myPostMimeContentbinding.Type = "application/x-www-form-urlencoded";
            myInputBinding.Extensions.Add(myPostMimeContentbinding);
            // Add the 'InputBinding' to 'OperationBinding'.
            myOperationBinding.Input = myInputBinding;
            OutputBinding  myOutputBinding      = new OutputBinding();
            MimeXmlBinding myPostMimeXmlbinding = new MimeXmlBinding();
            myPostMimeXmlbinding.Part = "Body";
            myOutputBinding.Extensions.Add(myPostMimeXmlbinding);
            // Add the 'OutPutBinding' to 'OperationBinding'.
            myOperationBinding.Output = myOutputBinding;
            // Add the 'OperationBinding' to 'Binding'.
            myBinding.Operations.Add(myOperationBinding);
            // Add the 'Binding' to 'BindingCollection' of 'ServiceDescription'.
            myDescription.Bindings.Add(myBinding);
            Port myPostPort = new Port();
            myPostPort.Name    = "Operation_2_ServiceHttpPost";
            myPostPort.Binding = new XmlQualifiedName("s0:Operation_2_ServiceHttpPost");
            HttpAddressBinding myPostAddressBinding = new HttpAddressBinding();
            myPostAddressBinding.Location =
                "http://localhost/Operation_2/Operation_2_Service.cs.asmx";
            // Add the 'HttpAddressBinding' to the 'Port'.
            myPostPort.Extensions.Add(myPostAddressBinding);
            // Add the 'Port' to 'PortCollection' of 'ServiceDescription'.
            myDescription.Services[0].Ports.Add(myPostPort);
            PortType myPostPortType = new PortType();
            myPostPortType.Name = "Operation_2_ServiceHttpPost";
            Operation myPostOperation = new Operation();
            myPostOperation.Name = "AddNumbers";
            OperationMessage myPostOperationInput = (OperationMessage) new OperationInput();
            myPostOperationInput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostIn");
            OperationMessage myPostOperationOutput = (OperationMessage) new OperationOutput();
            myPostOperationOutput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostout");
            myPostOperation.Messages.Add(myPostOperationInput);
            myPostOperation.Messages.Add(myPostOperationOutput);
            // Add the 'Operation' to 'PortType'.
            myPostPortType.Operations.Add(myPostOperation);
            // Adds the 'PortType' to 'PortTypeCollection' of 'ServiceDescription'.
            myDescription.PortTypes.Add(myPostPortType);
            Message myPostMessage1 = new Message();
            myPostMessage1.Name = "AddNumbersHttpPostIn";
            MessagePart myPostMessagePart1 = new MessagePart();
            myPostMessagePart1.Name = "firstnumber";
            myPostMessagePart1.Type = new XmlQualifiedName("s:string");
            MessagePart myPostMessagePart2 = new MessagePart();
            myPostMessagePart2.Name = "secondnumber";
            myPostMessagePart2.Type = new XmlQualifiedName("s:string");
            // Add the 'MessagePart' objects to 'Messages'.
            myPostMessage1.Parts.Add(myPostMessagePart1);
            myPostMessage1.Parts.Add(myPostMessagePart2);
            Message myPostMessage2 = new Message();
            myPostMessage2.Name = "AddNumbersHttpPostout";
            MessagePart myPostMessagePart3 = new MessagePart();
            myPostMessagePart3.Name    = "Body";
            myPostMessagePart3.Element = new XmlQualifiedName("s0:int");
            // Add the 'MessagePart' to 'Message'.
            myPostMessage2.Parts.Add(myPostMessagePart3);
            // Add the 'Message' objects to 'ServiceDescription'.
            myDescription.Messages.Add(myPostMessage1);
            myDescription.Messages.Add(myPostMessage2);
            // Write the 'ServiceDescription' as a WSDL file.
            myDescription.Write("Operation_2_Output_CS.wsdl");
            Console.WriteLine(" 'Operation_2_Output_CS.wsdl' file created Successfully");
// <Snippet1>
// <Snippet2>
            string    myString    = null;
            Operation myOperation = new Operation();
            myDescription = ServiceDescription.Read("Operation_2_Input_CS.wsdl");
            Message[] myMessage = new Message[myDescription.Messages.Count];

            // Copy the messages from the service description.
            myDescription.Messages.CopyTo(myMessage, 0);
            for (int i = 0; i < myDescription.Messages.Count; i++)
            {
                MessagePart[] myMessagePart =
                    new MessagePart[myMessage[i].Parts.Count];

                // Copy the message parts into a MessagePart.
                myMessage[i].Parts.CopyTo(myMessagePart, 0);
                for (int j = 0; j < myMessage[i].Parts.Count; j++)
                {
                    myString += myMessagePart[j].Name;
                    myString += " ";
                }
            }
            // Set the ParameterOrderString equal to the list of
            // message part names.
            myOperation.ParameterOrderString = myString;
            string[] myString1 = myOperation.ParameterOrder;
            int      k         = 0;
            Console.WriteLine("The list of message part names is as follows:");
            while (k < 5)
            {
                Console.WriteLine(myString1[k]);
                k++;
            }
// </Snippet2>
// </Snippet1>
        }
        catch (Exception e)
        {
            Console.WriteLine("The following Exception is raised : " + e.Message);
        }
    }
    public static void Main()
    {
        try
        {
            // Read the Existing Wsdl.
            ServiceDescription myServiceDescription =
                ServiceDescription.Read("AddSubtractService_CS.wsdl");
            // Remove the service named "MathService".
            ServiceCollection myServiceDescriptionCollection =
                myServiceDescription.Services;
            myServiceDescriptionCollection.
            Remove(myServiceDescription.Services["MathService"]);
            // Build a new Service.
            Service myService = new Service();
            myService.Name = "MathService";

            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:MathServiceSoap");
            // Build a new Port for Soap.
            Port mySoapPort = new Port();
            mySoapPort.Name    = "MathServiceSoap";
            mySoapPort.Binding = myXmlQualifiedName;
            SoapAddressBinding mySoapAddressBinding =
                new SoapAddressBinding();
            mySoapAddressBinding.Location =
                "http://localhost/ServiceCollection_CopyTo/AddSubtractService_CS.asmx";
            mySoapPort.Extensions.Add(mySoapAddressBinding);

            // Build a new Port for HttpGet.
            XmlQualifiedName myXmlQualifiedName2 =
                new XmlQualifiedName("s0:MathServiceHttpGet");
            Port myHttpGetPort = new Port();
            myHttpGetPort.Name    = "MathServiceHttpGet";
            myHttpGetPort.Binding = myXmlQualifiedName2;
            HttpAddressBinding myHttpAddressBinding =
                new HttpAddressBinding();
            myHttpAddressBinding.Location =
                "http://localhost/ServiceCollection_CopyTo/AddSubtractService_CS.asmx";
            myHttpGetPort.Extensions.Add(myHttpAddressBinding);
            // Build a new Port for HttpPost.
            XmlQualifiedName myXmlQualifiedName3 =
                new XmlQualifiedName("s0:MathServiceHttpPost");
            // Build a new Port for Soap.
            Port myHttpPostPort = new Port();
            myHttpPostPort.Name    = "MathServiceHttpPost";
            myHttpPostPort.Binding = myXmlQualifiedName3;
            HttpAddressBinding myHttpAddressBinding1 =
                new HttpAddressBinding();
            myHttpAddressBinding1.Location =
                "http://localhost/ServiceCollection_CopyTo/AddSubtractService_CS.asmx";
            myHttpPostPort.Extensions.Add(myHttpAddressBinding1);

            // Add the ports to the service.
            myService.Ports.Add(mySoapPort);
            myService.Ports.Add(myHttpGetPort);
            myService.Ports.Add(myHttpPostPort);
            // Add the Service to the ServiceCollection.
            myServiceDescription.Services.Insert(1, myService);
            StreamWriter myStreamWriter = new StreamWriter("output.wsdl");
            // Output the Wsdl.
            myServiceDescription.Write(myStreamWriter);
            myStreamWriter.Close();

// <Snippet1>
// <Snippet2>
            if (myServiceDescription.Services.Contains(myService))
            {
                Console.WriteLine(
                    "The mentioned service exists at index {0} in the WSDL.",
                    myServiceDescription.Services.IndexOf(myService));
// <Snippet3>
                Service[] myServiceArray =
                    new Service[myServiceDescription.Services.Count];

                // Copy the services into an array.
                myServiceDescription.Services.CopyTo(myServiceArray, 0);
                IEnumerator myEnumerator = myServiceArray.GetEnumerator();
                Console.WriteLine("The names of services in the array are");
                while (myEnumerator.MoveNext())
                {
                    Service myService1 = (Service)myEnumerator.Current;
                    Console.WriteLine(myService1.Name);
                }
// </Snippet3>
            }
            else
            {
                Console.WriteLine("Service does not exist in the WSDL.");
            }
// </Snippet2>
// </Snippet1>
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception Caught! " + e.Message);
        }
    }
Exemple #9
0
    public static void Main()
    {
        ServiceDescription myDescription = ServiceDescription.Read("HttpBinding_ctor_Input_CS.wsdl");
// <Snippet1>
// <Snippet2>
        // Create 'Binding' object.
        Binding myBinding = new Binding();

        myBinding.Name = "MyHttpBindingServiceHttpPost";
        XmlQualifiedName qualifiedName = new XmlQualifiedName("s0:MyHttpBindingServiceHttpPost");

        myBinding.Type = qualifiedName;
        // Create 'HttpBinding' object.
        HttpBinding myHttpBinding = new HttpBinding();

        myHttpBinding.Verb = "POST";
        Console.WriteLine("HttpBinding Namespace : " + HttpBinding.Namespace);
// </Snippet2>
        // Add 'HttpBinding' to 'Binding'.
        myBinding.Extensions.Add(myHttpBinding);
// </Snippet1>
        // Create 'OperationBinding' object.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "AddNumbers";
        HttpOperationBinding myOperation = new HttpOperationBinding();

        myOperation.Location = "/AddNumbers";
        // Add 'HttpOperationBinding' to 'OperationBinding'.
        myOperationBinding.Extensions.Add(myOperation);
        // Create 'InputBinding' object.
        InputBinding       myInput = new InputBinding();
        MimeContentBinding postMimeContentbinding = new MimeContentBinding();

        postMimeContentbinding.Type = "application/x-www-form-urlencoded";
        myInput.Extensions.Add(postMimeContentbinding);
        // Add 'InputBinding' to 'OperationBinding'.
        myOperationBinding.Input = myInput;
        // Create 'OutputBinding' object.
        OutputBinding  myOutput           = new OutputBinding();
        MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();

        postMimeXmlbinding.Part = "Body";
        myOutput.Extensions.Add(postMimeXmlbinding);
        // Add 'OutPutBinding' to 'OperationBinding'.
        myOperationBinding.Output = myOutput;
        // Add 'OperationBinding' to 'Binding'.
        myBinding.Operations.Add(myOperationBinding);
        // Add 'Binding' to 'BindingCollection' of 'ServiceDescription'.
        myDescription.Bindings.Add(myBinding);
// <Snippet3>
        // Create a 'Port' object.
        Port postPort = new Port();

        postPort.Name    = "MyHttpBindingServiceHttpPost";
        postPort.Binding = new XmlQualifiedName("s0:MyHttpBindingServiceHttpPost");
        // Create 'HttpAddressBinding' object.
        HttpAddressBinding postAddressBinding = new HttpAddressBinding();

        postAddressBinding.Location = "http://localhost/HttpBinding_ctor/HttpBinding_ctor_Service.cs.asmx";
        // Add 'HttpAddressBinding' to 'Port'.
        postPort.Extensions.Add(postAddressBinding);
// </Snippet3>
        // Add 'Port' to 'PortCollection' of 'ServiceDescription'.
        myDescription.Services[0].Ports.Add(postPort);
        // Write 'ServiceDescription' as a WSDL file.
        myDescription.Write("HttpBinding_ctor_Output_CS.wsdl");
        Console.WriteLine("WSDL file with name 'HttpBinding_ctor_Output_CS.wsdl' file created Successfully");
    }
// <Snippet1>
    public static void MyMethod(
        ServiceDescriptionBaseCollection myServiceCollection)
    {
        Type myType = myServiceCollection.GetType();

        if (myType.Equals(
                typeof(System.Web.Services.Description.ServiceCollection)))
        {
            // Remove the services at index 0 of the collection.
            ((ServiceCollection)myServiceCollection).Remove(
                myServiceDescription.Services[0]);

            // Build a new Service.
            Service myService = new Service();
            myService.Name = "MathService";
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:MathServiceSoap");

            // Build a new Port for SOAP.
            Port mySoapPort = new Port();
            mySoapPort.Name    = "MathServiceSoap";
            mySoapPort.Binding = myXmlQualifiedName;
            SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();
            mySoapAddressBinding.Location = "http://localhost/" +
                                            "ServiceDescriptionBaseCollection/AddSubtractService.CS.asmx";
            mySoapPort.Extensions.Add(mySoapAddressBinding);

            // Build a new Port for HTTP-GET.
            XmlQualifiedName myXmlQualifiedName2 =
                new XmlQualifiedName("s0:MathServiceHttpGet");
            Port myHttpGetPort = new Port();
            myHttpGetPort.Name    = "MathServiceHttpGet";
            myHttpGetPort.Binding = myXmlQualifiedName2;
            HttpAddressBinding myHttpAddressBinding = new HttpAddressBinding();
            myHttpAddressBinding.Location = "http://localhost/" +
                                            "ServiceDescriptionBaseCollection/AddSubtractService.CS.asmx";
            myHttpGetPort.Extensions.Add(myHttpAddressBinding);

            // Add the ports to the Service.
            myService.Ports.Add(myHttpGetPort);
            myService.Ports.Add(mySoapPort);

            // Add the Service to the ServiceCollection.
            myServiceDescription.Services.Add(myService);
        }
        else if (myType.Equals(
                     typeof(System.Web.Services.Description.BindingCollection)))
        {
            // Remove the Binding in the BindingCollection at index 0.
            ((BindingCollection)myServiceCollection).Remove(
                myServiceDescription.Bindings[0]);

            // Build a new Binding.
            Binding myBinding = new Binding();
            myBinding.Name = "MathServiceSoap";
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:MathServiceSoap");
            myBinding.Type = myXmlQualifiedName;
            SoapBinding mySoapBinding = new SoapBinding();
            mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";
            mySoapBinding.Style     = SoapBindingStyle.Document;

            // Create the operations for the binding.
            OperationBinding addOperationBinding = CreateOperationBinding(
                "Add", myServiceDescription.TargetNamespace);
            OperationBinding subtractOperationBinding = CreateOperationBinding(
                "Subtract", myServiceDescription.TargetNamespace);

            // Add the operations to the Binding.
            myBinding.Operations.Add(subtractOperationBinding);
            myBinding.Operations.Add(addOperationBinding);
            myBinding.Extensions.Add(mySoapBinding);

            // Add the Binding to the Bindings collection.
            myServiceDescription.Bindings.Add(myBinding);
        }
        else if (myType.Equals(
                     typeof(System.Web.Services.Description.PortTypeCollection)))
        {
            // Remove the PortType at index 0.
            ((PortTypeCollection)myServiceCollection).Remove(
                myServiceDescription.PortTypes[0]);

            // Build a new PortType.
            PortType myPortType = new PortType();
            myPortType.Name = "MathServiceSoap";

            // Build an Add Operation for the PortType.
            Operation myAddOperation = new Operation();
            myAddOperation.Name = "Add";

            // Build the Input and Output messages for the Operations.
            OperationInput   myOperationInputMessage1 = new OperationInput();
            XmlQualifiedName myXmlQualifiedName1      =
                new XmlQualifiedName("s0:AddSoapIn");
            myOperationInputMessage1.Message = myXmlQualifiedName1;

            OperationOutput  myOperationOutputMessage1 = new OperationOutput();
            XmlQualifiedName myXmlQualifiedName2       =
                new XmlQualifiedName("s0:AddSoapOut");
            myOperationOutputMessage1.Message = myXmlQualifiedName2;

            // Add the messages to the operations.
            myAddOperation.Messages.Add(myOperationInputMessage1);
            myAddOperation.Messages.Add(myOperationOutputMessage1);

            // Build an Add Operation for the PortType.
            Operation mySubtractOperation = new Operation();
            mySubtractOperation.Name = "Subtract";

            // Build the Input and Output messages for the operations.
            OperationInput   myOperationInputMessage2 = new OperationInput();
            XmlQualifiedName myXmlQualifiedName3      =
                new XmlQualifiedName("s0:SubtractSoapIn");
            myOperationInputMessage2.Message = myXmlQualifiedName3;
            OperationOutput  myOperationOutputMessage2 = new OperationOutput();
            XmlQualifiedName myXmlQualifiedName4       =
                new XmlQualifiedName("s0:SubtractSoapOut");
            myOperationOutputMessage2.Message = myXmlQualifiedName4;

            // Add the messages to the operations.
            mySubtractOperation.Messages.Add(myOperationInputMessage2);
            mySubtractOperation.Messages.Add(myOperationOutputMessage2);

            // Add the operations to the PortType.
            myPortType.Operations.Add(myAddOperation);
            myPortType.Operations.Add(mySubtractOperation);

            // Add the PortType to the collection.
            myServiceDescription.PortTypes.Add(myPortType);
        }
    }
    public static void Main()
    {
        try
        {
// <Snippet1>
// <Snippet2>
            // Create a new XmlTextWriter with specified URL.
            XmlTextReader      myXmlReader          = new XmlTextReader("All_CS.wsdl");
            ServiceDescription myServiceDescription =
                ServiceDescription.Read(myXmlReader);
            myServiceDescription.TargetNamespace = "http://tempuri.org/";

            // Remove the service named MathService.
            ServiceCollection myServiceDescriptionCollection =
                myServiceDescription.Services;
            myServiceDescriptionCollection.Remove(
                myServiceDescription.Services["MathService"]);
// </Snippet2>
// </Snippet1>

// <Snippet3>
            Service myService = new Service();
            myService.Name = "MathService";
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:MathServiceSoap");

            // Build a new Port for SOAP.
            Port mySoapPort = new Port();
            mySoapPort.Name    = "MathServiceSoap";
            mySoapPort.Binding = myXmlQualifiedName;
            SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();
            mySoapAddressBinding.Location =
                "http://localhost/ServiceDescription_Read/AddService_CS.asmx";
            mySoapPort.Extensions.Add(mySoapAddressBinding);

            // Build a new Port for HTTP-GET.
            XmlQualifiedName myXmlQualifiedName2 =
                new XmlQualifiedName("s0:MathServiceHttpGet");
            Port myHttpGetPort = new Port();
            myHttpGetPort.Name    = "MathServiceHttpGet";
            myHttpGetPort.Binding = myXmlQualifiedName2;
            HttpAddressBinding myHttpAddressBinding = new HttpAddressBinding();
            myHttpAddressBinding.Location =
                "http://localhost/ServiceDescription_Read/AddService_CS.asmx";
            myHttpGetPort.Extensions.Add(myHttpAddressBinding);

            // Add the ports to the service.
            myService.Ports.Add(myHttpGetPort);
            myService.Ports.Add(mySoapPort);

            // Add the service to the ServiceCollection.
            myServiceDescription.Services.Insert(1, myService);
// </Snippet3>

// <Snippet4>
            // Create a new XmlTextWriter object.
            XmlTextWriter myWriter = new XmlTextWriter("output.wsdl", Encoding.UTF8);
            myWriter.Formatting = Formatting.Indented;

            // Write the WSDL.
            myServiceDescription.Write(myWriter);
// </Snippet4>
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }