// <Snippet1> // <Snippet2> static void Main() { string myWsdlFileName = "MyWsdl_CS.wsdl"; XmlTextReader myReader = new XmlTextReader(myWsdlFileName); if (ServiceDescription.CanRead(myReader)) { ServiceDescription myDescription = ServiceDescription.Read(myWsdlFileName); // Remove the PortType at index 0 of the collection. PortTypeCollection myPortTypeCollection = myDescription.PortTypes; myPortTypeCollection.Remove(myDescription.PortTypes[0]); // Build a new PortType. PortType myPortType = new PortType(); myPortType.Name = "Service1Soap"; Operation myOperation = CreateOperation("Add", "s0:AddSoapIn", "s0:AddSoapOut", ""); myPortType.Operations.Add(myOperation); // Add a new PortType to the PortType collection of // the ServiceDescription. myDescription.PortTypes.Add(myPortType); myDescription.Write("MyOutWsdl.wsdl"); Console.WriteLine("New WSDL file generated successfully."); } else { Console.WriteLine("This file is not a WSDL file."); } }
public void InitializePortTypeCollection() { // workaround for internal constructor ServiceDescription desc = new ServiceDescription(); ptc = desc.PortTypes; }
public static void Main() { // Read the 'StockQuote.wsdl' file as input. ServiceDescription myServiceDescription = ServiceDescription.Read("StockQuote.wsdl"); // Get the operation fault collection and remove the operation fault with the name 'ErrorString'. PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; PortType myPortType = myPortTypeCollection[0]; OperationCollection myOperationCollection = myPortType.Operations; Operation myOperation = myOperationCollection[0]; OperationFaultCollection myOperationFaultCollection = myOperation.Faults; if (myOperationFaultCollection.Contains(myOperationFaultCollection["ErrorString"])) { myOperationFaultCollection.Remove(myOperationFaultCollection["ErrorString"]); } // Get the fault binding collection and remove the fault binding with the name 'ErrorString'. // <Snippet1> BindingCollection myBindingCollection = myServiceDescription.Bindings; Binding myBinding = myBindingCollection[0]; OperationBindingCollection myOperationBindingCollection = myBinding.Operations; OperationBinding myOperationBinding = myOperationBindingCollection[0]; FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults; if (myFaultBindingCollection.Contains(myFaultBindingCollection["ErrorString"])) { myFaultBindingCollection.Remove(myFaultBindingCollection["ErrorString"]); } // </Snippet1> myServiceDescription.Write(Console.Out); }
public void loadWSDL(string wsdlString) { if (!wsdlString.Equals("")) { StringReader sr = new StringReader(wsdlString); XmlTextReader tx = new XmlTextReader(sr); ServiceDescription t = ServiceDescription.Read(tx); // Initialize a service description importer. ServiceDescription serviceDescription = t.Services[0].ServiceDescription; Types types = serviceDescription.Types; PortTypeCollection portTypes = serviceDescription.PortTypes; MessageCollection messages = serviceDescription.Messages; XmlSchema schema = types.Schemas[0]; PortType porttype = portTypes[0]; Operation operation = porttype.Operations[0]; OperationInput input = operation.Messages[0].Operation.Messages.Input; Message message = messages[input.Message.Name]; MessagePart messagePart = message.Parts[0]; // XmlSchemaObject fsdf = types.Schemas[0].Elements[messagePart.Element]; XmlSchema fsdf = types.Schemas[0]; if (fsdf == null) { Console.WriteLine("Test"); } StringWriter twriter = new StringWriter(); // TextWriter writer= new TextWriter(twriter); fsdf.Write(twriter); DataSet set = new DataSet(); StringReader sreader = new StringReader(twriter.ToString()); XmlTextReader xmlreader = new XmlTextReader(sreader); set.ReadXmlSchema(xmlreader); soap = new XmlDocument(); XmlNode node, envelope, header, body, securityHeader; node = soap.CreateXmlDeclaration("1.0", "ISO-8859-1", "yes"); soap.AppendChild(node); envelope = soap.CreateElement("s", "Envelope", "http://www.w3.org/2003/05/soap-envelope"); soap.AppendChild(envelope); body = soap.CreateElement("s", "Body", "http://www.w3.org/2003/05/soap-envelope"); XmlNode eingabe = soap.CreateElement("tns", set.Tables[0].ToString(), set.Tables[0].Namespace); DataTable table = set.Tables[0]; foreach (DataColumn tempColumn in table.Columns) { XmlNode neu = soap.CreateElement("tns", tempColumn.ColumnName, set.Tables[0].Namespace); eingabe.AppendChild(neu); } body.AppendChild(eingabe); envelope.AppendChild(body); mySettings.Soap = xmlToString(soap); } }
public static void Main() { try { // <Snippet1> // <Snippet2> // <Snippet3> // <Snippet4> ServiceDescription myServiceDescription = ServiceDescription.Read("MathService_CS.wsdl"); PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; int noOfPortTypes = myServiceDescription.PortTypes.Count; Console.WriteLine("\nTotal number of PortTypes: " + noOfPortTypes); PortType myNewPortType = myPortTypeCollection["MathServiceSoap"]; // </Snippet4> // Get the index in the collection. int index = myPortTypeCollection.IndexOf(myNewPortType); // </Snippet3> Console.WriteLine("Removing the PortType named " + myNewPortType.Name); // Remove the PortType from the collection. myPortTypeCollection.Remove(myNewPortType); noOfPortTypes = myServiceDescription.PortTypes.Count; Console.WriteLine("\nTotal number of PortTypes: " + noOfPortTypes); // Check whether the PortType exists in the collection. bool bContains = myPortTypeCollection.Contains(myNewPortType); Console.WriteLine("Port Type'" + myNewPortType.Name + "' exists: " + bContains); Console.WriteLine("Adding the PortType"); // Insert a new portType at the index location. myPortTypeCollection.Insert(index, myNewPortType); // </Snippet2> // Display the number of portTypes after adding a port. Console.WriteLine("Total number of PortTypes after " + "adding a new port: " + myServiceDescription.PortTypes.Count); bContains = myPortTypeCollection.Contains(myNewPortType); Console.WriteLine("Port Type'" + myNewPortType.Name + "' exists: " + bContains); myServiceDescription.Write("MathService_New.wsdl"); // </Snippet1> } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public static void Main() { try { // Read the 'MathService_Input_cs.wsdl' file. ServiceDescription myDescription = ServiceDescription.Read("MathService_Input_cs.wsdl"); PortTypeCollection myPortTypeCollection = myDescription.PortTypes; // Get the 'OperationCollection' for 'SOAP' protocol. OperationCollection myOperationCollection = myPortTypeCollection[0].Operations; Operation myOperation = new Operation(); myOperation.Name = "Add"; OperationMessage myOperationMessageInput = (OperationMessage) new OperationInput(); myOperationMessageInput.Message = new XmlQualifiedName ("AddSoapIn", myDescription.TargetNamespace); OperationMessage myOperationMessageOutput = (OperationMessage) new OperationOutput(); myOperationMessageOutput.Message = new XmlQualifiedName( "AddSoapOut", myDescription.TargetNamespace); myOperation.Messages.Add(myOperationMessageInput); myOperation.Messages.Add(myOperationMessageOutput); myOperationCollection.Add(myOperation); if (myOperationCollection.Contains(myOperation) == true) { Console.WriteLine("The index of the added 'myOperation' " + "operation is : " + myOperationCollection.IndexOf(myOperation)); } myOperationCollection.Remove(myOperation); // Insert the 'myOpearation' operation at the index '0'. myOperationCollection.Insert(0, myOperation); Console.WriteLine("The operation at index '0' is : " + myOperationCollection[0].Name); Operation[] myOperationArray = new Operation[ myOperationCollection.Count]; myOperationCollection.CopyTo(myOperationArray, 0); Console.WriteLine("The operation(s) in the collection are :"); for (int i = 0; i < myOperationCollection.Count; i++) { Console.WriteLine(" " + myOperationArray[i].Name); } myDescription.Write("MathService_New_cs.wsdl"); } catch (Exception e) { Console.WriteLine("Exception caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } }
public Parser(WSDescriber wsDesc, ref bool untrustedSSLSecureChannel, ref List <Param> respHeader, string customRequestHeader) { HttpWebRequest wr = GetHttpWebReq(wsDesc, customRequestHeader); HttpWebResponse wres = null; try { wres = (HttpWebResponse)wr.GetResponse(); } catch (WebException wex) { if (wex.Status == WebExceptionStatus.TrustFailure) { ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; wr = GetHttpWebReq(wsDesc, customRequestHeader); wres = (HttpWebResponse)wr.GetResponse(); untrustedSSLSecureChannel = true; } } if (wres != null) { for (int i = 0; i < wres.Headers.Count; ++i) { respHeader.Add(new Param() { Name = wres.Headers.Keys[i].ToLowerInvariant(), Value = wres.Headers[i].ToLowerInvariant() }); } try { StreamReader streamReader = new StreamReader(wres.GetResponseStream()); rawWSDL = XDocument.Parse(streamReader.ReadToEnd()); TextReader myTextReader = new StringReader(rawWSDL.ToString()); serviceDescription = ServiceDescription.Read(myTextReader); TargetNameSpace = serviceDescription.TargetNamespace; bindColl = serviceDescription.Bindings; portTypColl = serviceDescription.PortTypes; msgColl = serviceDescription.Messages; types = serviceDescription.Types; schemas = types.Schemas; } catch (Exception ex) { throw ex; } } }
public static void Main() { try { // Read the 'StockQuote.wsdl' file as input. ServiceDescription myServiceDescription = ServiceDescription. Read("StockQuote_cs.wsdl"); // Remove the operation fault with the name 'ErrorString'. PortTypeCollection myPortTypeCollection = myServiceDescription. PortTypes; PortType myPortType = myPortTypeCollection[0]; OperationCollection myOperationCollection = myPortType.Operations; Operation myOperation = myOperationCollection[0]; // <Snippet1> OperationFaultCollection myOperationFaultCollection = myOperation.Faults; OperationFault myOperationFault = myOperationFaultCollection["ErrorString"]; if (myOperationFault != null) { myOperationFaultCollection.Remove(myOperationFault); } // </Snippet1> // Remove the fault binding with the name 'ErrorString'. BindingCollection myBindingCollection = myServiceDescription. Bindings; Binding myBinding = myBindingCollection[0]; OperationBindingCollection myOperationBindingCollection = myBinding.Operations; OperationBinding myOperationBinding = myOperationBindingCollection[0]; FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults; if (myFaultBindingCollection.Contains( myFaultBindingCollection["ErrorString"])) { myFaultBindingCollection.Remove( myFaultBindingCollection["ErrorString"]); } myServiceDescription.Write("OperationFaultCollection_out.wsdl"); Console.WriteLine("WSDL file with name 'OperationFaultCollection_out.wsdl'" + " created Successfully"); } catch (Exception e) { Console.WriteLine("Exception caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } }
public static void Main() { try { // Read the existing Web service description file. ServiceDescription myServiceDescription = ServiceDescription.Read("MathService_CS.wsdl"); PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; int noOfPortTypes = myServiceDescription.PortTypes.Count; Console.WriteLine("\nTotal number of PortTypes: " + myServiceDescription.PortTypes.Count); // Get the first PortType in the collection. PortType myNewPortType = myPortTypeCollection["MathServiceSoap"]; int index = myPortTypeCollection.IndexOf(myNewPortType); Console.WriteLine("The PortType with the name " + myNewPortType.Name + " is at index: " + (index + 1)); Console.WriteLine("Removing the PortType: " + myNewPortType.Name); // Remove the PortType from the collection. myPortTypeCollection.Remove(myNewPortType); bool bContains = myPortTypeCollection.Contains(myNewPortType); Console.WriteLine("The PortType with the name " + myNewPortType.Name + " exists: " + bContains); Console.WriteLine("Total number of PortTypes after removing: " + myServiceDescription.PortTypes.Count); Console.WriteLine("Adding a PortType: " + myNewPortType.Name); // Add a new portType from the collection. myPortTypeCollection.Add(myNewPortType); // Display the number of portTypes after adding a port. Console.WriteLine("Total number of PortTypes after " + "adding a new port: " + myServiceDescription.PortTypes.Count); // List the PortTypes available in the WSDL document. foreach (PortType myPortType in myPortTypeCollection) { Console.WriteLine("The PortType name is: " + myPortType.Name); } myServiceDescription.Write("MathService_New.wsdl"); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public static void Main() { try { // <Snippet1> // <Snippet2> // <Snippet3> ServiceDescription myServiceDescription = ServiceDescription.Read("MathService_CS.wsdl"); PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; int noOfPortTypes = myServiceDescription.PortTypes.Count; Console.WriteLine("\nTotal number of PortTypes: " + myServiceDescription.PortTypes.Count); // Get the first PortType in the collection. PortType myNewPortType = myPortTypeCollection[0]; Console.WriteLine( "The PortType at index 0 is: " + myNewPortType.Name); Console.WriteLine("Removing the PortType " + myNewPortType.Name); // Remove the PortType from the collection. myPortTypeCollection.Remove(myNewPortType); // Display the number of PortTypes. Console.WriteLine("\nTotal number of PortTypes after removing: " + myServiceDescription.PortTypes.Count); Console.WriteLine("Adding a PortType " + myNewPortType.Name); // Add a new PortType from the collection. myPortTypeCollection.Add(myNewPortType); // Display the number of PortTypes after adding a port. Console.WriteLine("Total number of PortTypes after " + "adding a new port: " + myServiceDescription.PortTypes.Count); myServiceDescription.Write("MathService_New.wsdl"); // </Snippet3> // </Snippet2> // </Snippet1> } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public static void Main() { // Read a ServiceDescription of existing WSDL. myServiceDescription = ServiceDescription.Read("Input_CS.wsdl"); // Get the ServiceCollection of the ServiceDescription. ServiceCollection myServiceCollection = myServiceDescription.Services; MyMethod(myServiceCollection); BindingCollection myBindingCollection = myServiceDescription.Bindings; MyMethod(myBindingCollection); PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; MyMethod(myPortTypeCollection); myServiceDescription.Write("Output.Wsdl"); }
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); } }
public static void Main() { try { // Read the 'StockQuote.wsdl' file as input. ServiceDescription myServiceDescription = ServiceDescription. Read("StockQuote_cs.wsdl"); PortTypeCollection myPortTypeCollection = myServiceDescription. PortTypes; PortType myPortType = myPortTypeCollection[0]; OperationCollection myOperationCollection = myPortType.Operations; Operation myOperation = myOperationCollection[0]; // <Snippet1> OperationFaultCollection myOperationFaultCollection = myOperation.Faults; OperationFault myOperationFault = new OperationFault(); myOperationFault.Name = "ErrorString"; myOperationFault.Message = new XmlQualifiedName("s0:GetTradePriceStringFault"); myOperationFaultCollection.Add(myOperationFault); // </Snippet1> Console.WriteLine("Added OperationFault with Name: " + myOperationFault.Name); myOperationFault = new OperationFault(); myOperationFault.Name = "ErrorInt"; myOperationFault.Message = new XmlQualifiedName ("s0:GetTradePriceIntFault"); myOperationFaultCollection.Add(myOperationFault); myOperationCollection.Add(myOperation); Console.WriteLine("Added Second OperationFault with Name: " + myOperationFault.Name); myServiceDescription.Write("StockQuoteNew_cs.wsdl"); Console.WriteLine("\nThe file 'StockQuoteNew_cs.wsdl' is created" + " successfully."); } catch (Exception e) { Console.WriteLine("Exception caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } }
/// <summary> /// Get list of Operations defined for the service /// </summary> /// <returns>List of Operations for the service</returns> public Operation[] GetOperations() { Operation[] result = null; ArrayList operations = new ArrayList(); PortTypeCollection portTypeCollection = serviceDescription.PortTypes; foreach (PortType portType in portTypeCollection) { OperationCollection operationCollection = portType.Operations; foreach (Operation operation in operationCollection) { operations.Add(operation); } } if (operations.Count > 0) { result = new Operation[operations.Count]; operations.CopyTo(result, 0); } return(result); }
public static void Main() { // <Snippet1> // Read the 'Operation_Faults_Input_CS.wsdl' file as input. ServiceDescription myServiceDescription = ServiceDescription.Read("Operation_Faults_Input_CS.wsdl"); // Get the operation fault collection. PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; PortType myPortType = myPortTypeCollection[0]; OperationCollection myOperationCollection = myPortType.Operations; // Remove the operation fault with the name 'ErrorString'. Operation myOperation = myOperationCollection[0]; OperationFaultCollection myOperationFaultCollection = myOperation.Faults; if (myOperationFaultCollection.Contains(myOperationFaultCollection["ErrorString"])) { myOperationFaultCollection.Remove(myOperationFaultCollection["ErrorString"]); } // </Snippet1> // Get the fault binding collection. BindingCollection myBindingCollection = myServiceDescription.Bindings; Binding myBinding = myBindingCollection[0]; OperationBindingCollection myOperationBindingCollection = myBinding.Operations; // Remove the fault binding with the name 'ErrorString'. OperationBinding myOperationBinding = myOperationBindingCollection[0]; FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults; if (myFaultBindingCollection.Contains(myFaultBindingCollection["ErrorString"])) { myFaultBindingCollection.Remove(myFaultBindingCollection["ErrorString"]); } myServiceDescription.Write("Operation_Faults_Output_CS.wsdl"); Console.WriteLine("WSDL file with name 'Operation_Faults_Output_CS.wsdl' file created Successfully"); }
private static PortType ConstructPortTypes(InterfaceContract serviceInterfaceContract, System.Web.Services.Description.ServiceDescription desc, string portTypeName) { PortTypeCollection portTypes = desc.PortTypes; PortType portType = new PortType(); portType.Name = portTypeName; portType.Documentation = serviceInterfaceContract.ServiceDocumentation; // Add each operation and it's corresponding in/out messages to the WSDL Port Type. foreach (Operation op in serviceInterfaceContract.Operations) { FxOperation tempOperation = new FxOperation(); tempOperation.Name = op.Name; tempOperation.Documentation = op.Documentation; int i = 0; OperationInput operationInput = new OperationInput(); operationInput.Message = new XmlQualifiedName(op.MessagesCollection[i].Name, desc.TargetNamespace); tempOperation.Messages.Add(operationInput); if (op.Mep == Mep.RequestResponse) { OperationOutput operationOutput = new OperationOutput(); operationOutput.Message = new XmlQualifiedName(op.MessagesCollection[i + 1].Name, desc.TargetNamespace); tempOperation.Messages.Add(operationOutput); } portType.Operations.Add(tempOperation); i++; } portTypes.Add(portType); return(portType); }
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); } }
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); }
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); } }
public static void Main() { // Read the 'StockQuote.wsdl' file as input. ServiceDescription myServiceDescription = ServiceDescription.Read("StockQuote.wsdl"); PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; PortType myPortType = myPortTypeCollection[0]; OperationCollection myOperationCollection = myPortType.Operations; Operation myOperation = myOperationCollection[0]; OperationFaultCollection myOperationFaultCollection = myOperation.Faults; // Reverse the operation fault order. if (myOperationFaultCollection.Count > 1) { OperationFault[] myOperationFaultArray = new OperationFault[myOperationFaultCollection.Count]; // Copy the operation fault to a temporary array. myOperationFaultCollection.CopyTo(myOperationFaultArray, 0); // Remove all the operation fault instances in the fault binding collection. for (int i = 0; i < myOperationFaultArray.Length; i++) { myOperationFaultCollection.Remove(myOperationFaultArray[i]); } // Insert the operation fault instance in the reverse order. for (int i = 0, j = (myOperationFaultArray.Length - 1); i < myOperationFaultArray.Length; i++, j--) { myOperationFaultCollection.Insert(i, myOperationFaultArray[j]); } } // <Snippet1> // <Snippet2> // <Snippet3> // <Snippet4> // <Snippet5> // <Snippet6> BindingCollection myBindingCollection = myServiceDescription.Bindings; Binding myBinding = myBindingCollection[0]; OperationBindingCollection myOperationBindingCollection = myBinding.Operations; OperationBinding myOperationBinding = myOperationBindingCollection[0]; FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults; // Reverse the fault bindings order. if (myFaultBindingCollection.Count > 1) { FaultBinding myFaultBinding = myFaultBindingCollection[0]; FaultBinding[] myFaultBindingArray = new FaultBinding[myFaultBindingCollection.Count]; // Copy the fault bindings to a temporary array. myFaultBindingCollection.CopyTo(myFaultBindingArray, 0); // Remove all the fault binding instances in the fault binding collection. for (int i = 0; i < myFaultBindingArray.Length; i++) { myFaultBindingCollection.Remove(myFaultBindingArray[i]); } // Insert the fault binding instance in the reverse order. for (int i = 0, j = (myFaultBindingArray.Length - 1); i < myFaultBindingArray.Length; i++, j--) { myFaultBindingCollection.Insert(i, myFaultBindingArray[j]); } // Check if the first element in the collection before the reversal is now the last element. if (myFaultBindingCollection.Contains(myFaultBinding) && myFaultBindingCollection.IndexOf(myFaultBinding) == (myFaultBindingCollection.Count - 1)) { // Display the WSDL generated to the console. myServiceDescription.Write(Console.Out); } else { Console.WriteLine("Error while reversing"); } } // </Snippet6> // </Snippet5> // </Snippet4> // </Snippet3> // </Snippet2> // </Snippet1> }
private void CheckSoap() { bool signatureValid = true; this.Compiled(); if (this._inputDocument == null) { return; } if (this._inputDocument.GetElementsByTagName("ds:Signature") != null) { this._validator = new SignatureValidator(this); } signatureValid = this._validator.Valid; object invokedObject = new object(); object[] parameters = null; string response; if (this._serviceDescription == null) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("There is no Web Service Description available", this, NotificationLevel.Error)); } else { if (!signatureValid) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("Signature validation failed", this, NotificationLevel.Error)); goto Abort; } Types types = this._serviceDescription.Types; PortTypeCollection portTypes = this._serviceDescription.PortTypes; MessageCollection messages = this._serviceDescription.Messages; PortType porttype = portTypes[0]; Operation operation = porttype.Operations[0]; OperationOutput output = operation.Messages[0].Operation.Messages.Output; OperationInput input = operation.Messages[0].Operation.Messages.Input; Message messageOutput = messages[output.Message.Name]; Message messageInput = messages[input.Message.Name]; MessagePart messageOutputPart = messageOutput.Parts[0]; MessagePart messageInputPart = messageInput.Parts[0]; XmlSchema xmlSchema = types.Schemas[0]; XmlSchemaElement outputSchema = (XmlSchemaElement)xmlSchema.Elements[messageOutputPart.Element]; XmlSchemaElement inputSchema = (XmlSchemaElement)xmlSchema.Elements[messageInputPart.Element]; XmlSchemaComplexType complexTypeOutput = (XmlSchemaComplexType)outputSchema.SchemaType; XmlSchemaSequence sequenzTypeOutput = (XmlSchemaSequence)complexTypeOutput.Particle; XmlSchemaComplexType complexTypeInput = (XmlSchemaComplexType)inputSchema.SchemaType; XmlSchemaSequence sequenzTypeInput = (XmlSchemaSequence)complexTypeInput.Particle; Hashtable paramTypesTable = new Hashtable(); StringWriter xmlStringWriter = new StringWriter(); xmlSchema.Write(xmlStringWriter); this._set = new DataSet(); StringReader sreader = new StringReader(xmlStringWriter.ToString()); XmlTextReader xmlreader = new XmlTextReader(sreader); this._set.ReadXmlSchema(xmlreader); if (sequenzTypeInput != null) { foreach (XmlSchemaElement inputParam in sequenzTypeInput.Items) { XmlQualifiedName schemaName = inputParam.SchemaTypeName; paramTypesTable.Add(inputParam.QualifiedName.Name, schemaName.Name); } XmlNamespaceManager manager = new XmlNamespaceManager(this._modifiedInputDocument.NameTable); XmlElement body = (XmlElement)this._inputDocument.GetElementsByTagName("s:Body")[0]; manager.AddNamespace("s", body.NamespaceURI); manager.AddNamespace("tns", "http://tempuri.org/"); XmlNode node = this._modifiedInputDocument.SelectSingleNode("s:Envelope/s:Body/" + "tns:" + this._set.Tables[0].TableName, manager); XmlElement ele = (XmlElement)node; int paramCounter = new Int32(); try { paramCounter = ele.ChildNodes.Count; } catch { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("Some params are missing", this, NotificationLevel.Error)); } if (paramCounter != 0) { parameters = new Object[paramCounter]; for (int i = 0; i < paramCounter; i++) { string param = ele.ChildNodes[i].InnerText; Object paramType = paramTypesTable[ele.ChildNodes[i].LocalName]; if (paramType.ToString().Equals("int")) { if (!ele.ChildNodes[i].InnerText.Equals("")) { try { parameters[i] = Convert.ToInt32((Object)ele.ChildNodes[i].InnerText); } catch (Exception e) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(e.Message, this, NotificationLevel.Error)); goto Abort; } } else { if (ele.ChildNodes[i].Name != null) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("Parameter " + ele.ChildNodes[i].Name + " is missing", this, NotificationLevel.Error)); } goto Abort; } } if (paramType.ToString().Equals("string")) { if (!ele.ChildNodes[i].InnerText.Equals("")) { try { parameters[i] = Convert.ToString((Object)ele.ChildNodes[i].InnerText); } catch (Exception e) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(e.Message, this, NotificationLevel.Error)); goto Abort; } } else { if (ele.ChildNodes[i].Name != null) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("Parameter " + ele.ChildNodes[i].Name + " is missing", this, NotificationLevel.Error)); } goto Abort; } } if (paramType.ToString().Equals("double")) { if (!ele.ChildNodes[i].InnerText.Equals("")) { try { parameters[i] = Convert.ToDouble((Object)ele.ChildNodes[i].InnerText); } catch (Exception e) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(e.Message, this, NotificationLevel.Error)); goto Abort; } } else { if (ele.ChildNodes[i].Name != null) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs("Parameter " + ele.ChildNodes[i].Name + " is missing", this, NotificationLevel.Error)); } goto Abort; } } } for (int i = 0; i < parameters.Length; i++) { if (parameters[i] == null) { goto Abort; } } try { Type typ = this._service.GetType().GetMethod(operation.Name).ReturnType; string returnType = typ.ToString(); if (!returnType.Equals("System.Void")) { invokedObject = this._service.GetType().GetMethod(operation.Name).Invoke(this._service, parameters).ToString(); } else { this._service.GetType().GetMethod(operation.Name).Invoke(this._service, parameters).ToString(); } } catch (Exception e) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(e.Message, this, NotificationLevel.Error)); goto Abort; } } else { if (sequenzTypeOutput != null) { try { invokedObject = this._service.GetType().GetMethod(operation.Name).Invoke(this._service, null).ToString(); } catch (Exception e) { EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(e.Message, this, NotificationLevel.Error)); goto Abort; } } else { this._service.GetType().GetMethod(operation.Name).Invoke(this._service, parameters); } } response = invokedObject.ToString(); this.CreateResponse(response); } } Abort :; }
public static void Main() { try { // Read the StockQuote.wsdl file as input. ServiceDescription myServiceDescription = ServiceDescription.Read("StockQuote_cs.wsdl"); // <Snippet2> // <Snippet3> // <Snippet4> // <Snippet5> // <Snippet6> // <Snippet7> PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes; PortType myPortType = myPortTypeCollection[0]; OperationCollection myOperationCollection = myPortType.Operations; Operation myOperation = myOperationCollection[0]; OperationFaultCollection myOperationFaultCollection = myOperation.Faults; // Reverse the operation fault order. if (myOperationFaultCollection.Count > 1) { OperationFault myOperationFault = myOperationFaultCollection[0]; OperationFault[] myOperationFaultArray = new OperationFault[myOperationFaultCollection.Count]; // Copy the operation faults to a temporary array. myOperationFaultCollection.CopyTo(myOperationFaultArray, 0); // Remove all the operation faults from the collection. for (int i = 0; i < myOperationFaultArray.Length; i++) { myOperationFaultCollection.Remove(myOperationFaultArray[i]); } // Insert the operation faults in the reverse order. for (int i = 0, j = (myOperationFaultArray.Length - 1); i < myOperationFaultArray.Length; i++, j--) { myOperationFaultCollection.Insert( i, myOperationFaultArray[j]); } if (myOperationFaultCollection.Contains(myOperationFault) && (myOperationFaultCollection.IndexOf(myOperationFault) == myOperationFaultCollection.Count - 1)) { Console.WriteLine( "Succeeded in reversing the operation faults."); } else { Console.WriteLine("Error while reversing the faults."); } } // </Snippet7> // </Snippet6> // </Snippet5> // </Snippet4> // </Snippet3> // </Snippet2> BindingCollection myBindingCollection = myServiceDescription.Bindings; Binding myBinding = myBindingCollection[0]; OperationBindingCollection myOperationBindingCollection = myBinding.Operations; OperationBinding myOperationBinding = myOperationBindingCollection[0]; FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults; // Reverse the fault binding order. if (myFaultBindingCollection.Count > 1) { FaultBinding myFaultBinding = myFaultBindingCollection[0]; FaultBinding[] myFaultBindingArray = new FaultBinding[myFaultBindingCollection.Count]; // Copy the fault bindings to a temporary array. myFaultBindingCollection.CopyTo(myFaultBindingArray, 0); // Remove all the fault bindings. for (int i = 0; i < myFaultBindingArray.Length; i++) { myFaultBindingCollection.Remove(myFaultBindingArray[i]); } // Insert the fault bindings in the reverse order. for (int i = 0, j = (myFaultBindingArray.Length - 1); i < myFaultBindingArray.Length; i++, j--) { myFaultBindingCollection.Insert(i, myFaultBindingArray[j]); } // Check whether the first element before the reversal // is now the last element. if (myFaultBindingCollection.Contains(myFaultBinding) && myFaultBindingCollection.IndexOf(myFaultBinding) == (myFaultBindingCollection.Count - 1)) { // Write the WSDL generated to a file. myServiceDescription.Write("StockQuoteOut_cs.wsdl"); Console.WriteLine( "The file StockQuoteOut_cs.wsdl was successfully written."); } else { Console.WriteLine( "An error occurred while reversing the input WSDL file."); } } } catch (Exception e) { Console.WriteLine("Exception caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } }