internal static bool ConvertSoapBinding(ref object src, EnvelopeVersion version) { SoapBinding binding = src as SoapBinding; if (src != null) { if (binding == null) { return(false); } if (GetBindingVersion <Soap12Binding>(src) == version) { return(true); } } if (version == EnvelopeVersion.None) { src = null; return(true); } SoapBinding binding2 = (version == EnvelopeVersion.Soap12) ? new Soap12Binding() : new SoapBinding(); if (binding != null) { binding2.Required = binding.Required; binding2.Style = binding.Style; binding2.Transport = binding.Transport; } src = binding2; return(true); }
public static void Main() { // <Snippet1> // <Snippet2> ServiceDescription myServiceDescription = new ServiceDescription(); myServiceDescription = ServiceDescription.Read("ServiceDescription_Extensions_Input_cs.wsdl"); Console.WriteLine( myServiceDescription.Bindings[1].Extensions[0].ToString()); SoapBinding mySoapBinding = new SoapBinding(); mySoapBinding.Required = true; SoapBinding mySoapBinding1 = new SoapBinding(); mySoapBinding1.Required = false; myServiceDescription.Extensions.Add(mySoapBinding); myServiceDescription.Extensions.Add(mySoapBinding1); foreach (ServiceDescriptionFormatExtension myServiceDescriptionFormatExtension in myServiceDescription.Extensions) { Console.WriteLine("Required: " + myServiceDescriptionFormatExtension.Required); } myServiceDescription.Write( "ServiceDescription_Extensions_Output_cs.wsdl"); myServiceDescription.RetrievalUrl = "http://www.contoso.com/"; Console.WriteLine("Retrieval URL is: " + myServiceDescription.RetrievalUrl); // </Snippet2> // </Snippet1> }
void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (context.Endpoint.Binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding"); } TransportBindingElement transportBindingElement = GetBindingElements(context).Find <TransportBindingElement>(); if ((transportBindingElement == null) || StateHelper.IsRegisteredTransportBindingElement(importer, context)) { SoapBinding soapBinding = (SoapBinding)context.WsdlBinding.Extensions.Find(typeof(SoapBinding)); if ((soapBinding != null) && (transportBindingElement == null)) { CreateLegacyTransportBindingElement(importer, soapBinding, context); } if (context.WsdlPort != null) { ImportAddress(context, transportBindingElement); } } }
private static SoapBinding GetSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExporter exporter) { EnvelopeVersion item = null; SoapBinding soapBinding = null; object obj = null; object obj1 = new object(); if (exporter.State.TryGetValue(obj1, out obj)) { Dictionary <System.Web.Services.Description.Binding, EnvelopeVersion> bindings = obj as Dictionary <System.Web.Services.Description.Binding, EnvelopeVersion>; if (bindings != null && bindings.ContainsKey(endpointContext.WsdlBinding)) { item = bindings[endpointContext.WsdlBinding]; } } if (item == EnvelopeVersion.None) { return(null); } foreach (object extension in endpointContext.WsdlBinding.Extensions) { SoapBinding soapBinding1 = extension as SoapBinding; if (soapBinding1 == null) { continue; } soapBinding = soapBinding1; } return(soapBinding); }
static void FuzzHttpGetPort(SoapBinding binding) { SoapPortType portType = _wsdl.PortTypes.Single(pt => pt.Name == binding.Type.Split(':')[1]); foreach (SoapBindingOperation op in binding.Operations) { Console.WriteLine("Fuzzing operation: " + op.Name); string url = _endpoint + op.Location; SoapOperation po = portType.Operations.Single(p => p.Name == op.Name); SoapMessage input = _wsdl.Messages.Single(m => m.Name == po.Input.Split(':')[1]); Dictionary <string, string> parameters = new Dictionary <string, string>(); foreach (SoapMessagePart part in input.Parts) { parameters.Add(part.Name, part.Type); } bool first = true; List <Guid> guidList = new List <Guid>(); foreach (var param in parameters) { if (param.Value.EndsWith("string")) { Guid guid = Guid.NewGuid(); guidList.Add(guid); url += (first ? "?" : "&") + param.Key + "=" + guid.ToString(); } first = false; } Console.WriteLine("Fuzzing full url: " + url); int k = 0; foreach (Guid guid in guidList) { string testUrl = url.Replace(guid.ToString(), "fd'sa"); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(testUrl); string resp = string.Empty; try { using (StreamReader rdr = new StreamReader(req.GetResponse().GetResponseStream())) resp = rdr.ReadToEnd(); } catch (WebException ex) { using (StreamReader rdr = new StreamReader(ex.Response.GetResponseStream())) resp = rdr.ReadToEnd(); if (resp.Contains("syntax error")) { Console.WriteLine("Possible SQL injection vector in parameter: " + input.Parts[k].Name); } } k++; } } }
public static void Main() { ServiceDescription myServiceDescription = ServiceDescription.Read("SoapHeaderBindingInput_cs.wsdl"); Binding myBinding = new Binding(); myBinding.Name = "MyWebServiceSoap"; myBinding.Type = new XmlQualifiedName("s0:MyWebServiceSoap"); SoapBinding mySoapBinding = new SoapBinding(); mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http"; mySoapBinding.Style = SoapBindingStyle.Document; myBinding.Extensions.Add(mySoapBinding); OperationBinding myOperationBinding = new OperationBinding(); myOperationBinding.Name = "Hello"; SoapOperationBinding mySoapOperationBinding = new SoapOperationBinding(); mySoapOperationBinding.SoapAction = "http://tempuri.org/Hello"; mySoapOperationBinding.Style = SoapBindingStyle.Document; myOperationBinding.Extensions.Add(mySoapOperationBinding); // Create InputBinding for operation for the 'SOAP' protocol. InputBinding myInputBinding = new InputBinding(); SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding(); mySoapBodyBinding.Use = SoapBindingUse.Literal; myInputBinding.Extensions.Add(mySoapBodyBinding); SoapHeaderBinding mySoapHeaderBinding = new SoapHeaderBinding(); mySoapHeaderBinding.Message = new XmlQualifiedName("s0:HelloMyHeader"); mySoapHeaderBinding.Part = "MyHeader"; mySoapHeaderBinding.Use = SoapBindingUse.Literal; // Add mySoapHeaderBinding to 'myInputBinding' object. myInputBinding.Extensions.Add(mySoapHeaderBinding); // Create OutputBinding for operation for the 'SOAP' protocol. OutputBinding myOutputBinding = new OutputBinding(); myOutputBinding.Extensions.Add(mySoapBodyBinding); // Add 'InputBinding' and 'OutputBinding' to 'OperationBinding'. myOperationBinding.Input = myInputBinding; myOperationBinding.Output = myOutputBinding; myBinding.Operations.Add(myOperationBinding); myServiceDescription.Bindings.Add(myBinding); myServiceDescription.Write("SoapHeaderBindingOut_cs.wsdl"); Console.WriteLine("'SoapHeaderBindingOut_cs.wsdl' file is generated."); Console.WriteLine("Proxy could be created using " + "'wsdl SoapHeaderBindingOut_cs.wsdl'."); }
internal static SoapBindingStyle GetStyle(Binding binding) { SoapBindingStyle style = SoapBindingStyle.Default; if (binding != null) { SoapBinding binding2 = binding.Extensions.Find(typeof(SoapBinding)) as SoapBinding; if (binding2 != null) { style = binding2.Style; } } return(style); }
internal static SoapBinding GetOrCreateSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExporter exporter) { if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None) { return(null); } SoapBinding soapBinding = GetSoapBinding(endpointContext); if (soapBinding != null) { return(soapBinding); } return(CreateSoapBinding(GetSoapVersion(endpointContext.WsdlBinding), endpointContext.WsdlBinding)); }
private static SoapBinding CreateSoapBinding(EnvelopeVersion version, Binding wsdlBinding) { SoapBinding extension = null; if (version == EnvelopeVersion.Soap12) { extension = new Soap12Binding(); } else if (version == EnvelopeVersion.Soap11) { extension = new SoapBinding(); } wsdlBinding.Extensions.Add(extension); return(extension); }
static void FuzzHttpPort(SoapBinding binding) { if (binding.Verb == "GET") { FuzzHttpGetPort(binding); } else if (binding.Verb == "POST") { FuzzHttpPostPort(binding); } else { throw new Exception("Don't know Verb: " + binding.Verb); } }
static void Run() { try { // <Snippet2> // 'dataservice.disco' is a sample discovery document. string myStringUrl = "http://localhost/dataservice.disco"; // Call the Discover method to populate the Documents property. DiscoveryClientProtocol myDiscoveryClientProtocol = new DiscoveryClientProtocol(); myDiscoveryClientProtocol.Credentials = CredentialCache.DefaultCredentials; DiscoveryDocument myDiscoveryDocument = myDiscoveryClientProtocol.Discover(myStringUrl); Console.WriteLine("Demonstrating the Discovery.SoapBinding class."); // Create a SOAP binding. SoapBinding mySoapBinding = new SoapBinding(); // Assign an address to the created SOAP binding. mySoapBinding.Address = "http://schemas.xmlsoap.org/disco/scl/"; // Bind the created SOAP binding with a new XmlQualifiedName. mySoapBinding.Binding = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // Add the created SOAP binding to the DiscoveryClientProtocol. myDiscoveryClientProtocol.AdditionalInformation.Add(mySoapBinding); // Display the namespace associated with SOAP binding. Console.WriteLine("Namespace associated with the SOAP binding is: " + SoapBinding.Namespace); // Write all the information of the DiscoveryClientProtocol. myDiscoveryClientProtocol.WriteAll(".", "results.discomap"); // </Snippet2> } catch (Exception e) { Console.WriteLine(e.ToString()); } }
static void FuzzService(SoapService service) { Console.WriteLine("Fuzzing service: " + service.Name); foreach (SoapPort port in service.Ports) { Console.WriteLine("Fuzzing " + port.ElementType.Split(':')[0] + "port: " + port.Name); SoapBinding binding = _wsdl.Bindings.Single(b => b.Name == port.Binding.Split(':')[1]); if (binding.IsHTTP) { FuzzHttpPort(binding); } else { FuzzSoapPort(binding); } } }
private static object GetSoapBinding(System.ServiceModel.Channels.Binding binding) { if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap11) { SoapBinding soapBinding = new SoapBinding(); soapBinding.Transport = GetTransport(binding); soapBinding.Style = SoapBindingStyle.Document; return(soapBinding); } else if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap12) { Soap12Binding soapBinding = new Soap12Binding(); soapBinding.Transport = GetTransport(binding); soapBinding.Style = SoapBindingStyle.Document; return(soapBinding); } return(null); }
void System.ServiceModel.Description.IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context) { if (context.WsdlPort != null) { ServiceEndpoint endpoint = context.Endpoint; EndpointAddress endpointAddress = WSAddressingHelper.ImportAddress(context.WsdlPort); EndpointAddress endpointAddress1 = endpointAddress; endpoint.Address = endpointAddress; EndpointAddress endpointAddress2 = endpointAddress1; if (endpointAddress2 != null) { context.Endpoint.Address = endpointAddress2; } } SoapBinding soapBinding = (SoapBinding)context.WsdlBinding.Extensions.Find(typeof(SoapBinding)); soapBinding.Handled = true; }
void CheckBasicHttpBinding(WSServiceDescription wsd, string binding_name, XmlQualifiedName binding_type, string operation_name, string action, bool has_input, bool has_output, string label) { WSBinding b = GetBinding(wsd, binding_name, label); OperationBinding op = GetOperationBinding(b, operation_name, label + " CheckBasicHttpBinding"); Assert.AreEqual(binding_type, b.Type, label + " #cbh0"); if (has_input) { InputBinding inb = op.Input; Assert.IsNotNull(inb, label + " #cbh1"); Assert.AreEqual(1, inb.Extensions.Count, label + " #cbh2"); Assert.AreEqual(typeof(SoapBodyBinding), inb.Extensions [0].GetType(), label + " #cbh3"); SoapBodyBinding soap_binding = (SoapBodyBinding)inb.Extensions [0]; Assert.AreEqual(SoapBindingUse.Literal, soap_binding.Use, label + " #cbh4"); if (action != null) { Assert.AreEqual(1, op.Extensions.Count, label + " #chb5"); Assert.AreEqual(typeof(SoapOperationBinding), op.Extensions [0].GetType(), label + " #cbh6"); SoapOperationBinding sopb = (SoapOperationBinding)op.Extensions [0]; Assert.AreEqual(action, sopb.SoapAction, label + " #cbh7"); } } if (has_output) { OutputBinding outb = op.Output; Assert.IsNotNull(outb, label + " #cbh10"); Assert.AreEqual(1, outb.Extensions.Count, label + " #cbh11"); Assert.AreEqual(typeof(SoapBodyBinding), outb.Extensions [0].GetType(), label + " #cbh12"); SoapBodyBinding soap_binding = (SoapBodyBinding)outb.Extensions [0]; Assert.AreEqual(SoapBindingUse.Literal, soap_binding.Use, label + " #cbh13"); } Assert.AreEqual(1, b.Extensions.Count, label + " #cbh20"); Assert.AreEqual(typeof(SoapBinding), b.Extensions [0].GetType(), label + " #cbh21"); SoapBinding sb = (SoapBinding)b.Extensions [0]; Assert.AreEqual(SoapBinding.HttpTransport, sb.Transport, label + " #cbh22"); }
void System.ServiceModel.Description.IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context) { MessageEncodingBindingElement messageEncodingBindingElement = context.Endpoint.Binding.CreateBindingElements().Find <MessageEncodingBindingElement>(); if (messageEncodingBindingElement == null) { messageEncodingBindingElement = Microsoft.ServiceBus.Messaging.Channels.TransportDefaults.CreateDefaultEncoder(); } SoapBinding soapBinding = NetMessagingTransportBindingElement.GetSoapBinding(context, exporter); if (soapBinding != null) { soapBinding.Transport = "http://sample.schemas.microsoft.com/policy/netMessaging"; } if (context.WsdlPort != null) { WSAddressingHelper.AddAddressToWsdlPort(context.WsdlPort, context.Endpoint.Address, messageEncodingBindingElement.MessageVersion.Addressing); } }
internal void ExportMessageBinding(OperationDescription operation, Type messageContractExporterType) { bool flag; bool flag2; OperationBinding operationBinding = this.endpointContext.GetOperationBinding(operation); if (GetStyleAndUse(operation, messageContractExporterType, out flag, out flag2)) { SoapOperationBinding binding2 = SoapHelper.GetOrCreateSoapOperationBinding(this.endpointContext, operation, this.exporter); if (binding2 != null) { binding2.Style = flag ? SoapBindingStyle.Rpc : SoapBindingStyle.Document; if (flag) { SoapBinding binding3 = (SoapBinding)this.endpointContext.WsdlBinding.Extensions.Find(typeof(SoapBinding)); binding3.Style = binding2.Style; } binding2.SoapAction = operation.Messages[0].Action; foreach (MessageDescription description in operation.Messages) { Message message; MessageBinding messageBinding = this.endpointContext.GetMessageBinding(description); if (this.exportedMessages.WsdlHeaderMessages.TryGetValue(new MessageContractExporter.MessageDescriptionDictionaryKey(this.endpointContext.Endpoint.Contract, description), out message)) { XmlQualifiedName messageName = new XmlQualifiedName(message.Name, message.ServiceDescription.TargetNamespace); foreach (MessageHeaderDescription description2 in description.Headers) { if (!description2.IsUnknownHeaderCollection) { this.ExportMessageHeaderBinding(description2, messageName, flag2, messageBinding); } } } this.ExportMessageBodyBinding(description, flag, flag2, messageBinding); } foreach (FaultDescription description3 in operation.Faults) { this.ExportFaultBinding(description3, flag2, operationBinding); } } } }
static void Main() { try { // <Snippet1> // Obtain the ServiceDescription from existing WSDL. ServiceDescription myDescription = ServiceDescription.Read("MyWsdl_CS.wsdl"); // Remove the Binding from the BindingCollection of // the ServiceDescription. BindingCollection myBindingCollection = myDescription.Bindings; myBindingCollection.Remove(myBindingCollection[0]); // Form a new Binding. Binding myBinding = new Binding(); myBinding.Name = "Service1Soap"; XmlQualifiedName myXmlQualifiedName = new XmlQualifiedName("s0:Service1Soap"); myBinding.Type = myXmlQualifiedName; SoapBinding mySoapBinding = new SoapBinding(); mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http"; mySoapBinding.Style = SoapBindingStyle.Document; OperationBinding addOperationBinding = CreateOperationBinding("Add", myDescription.TargetNamespace); myBinding.Operations.Add(addOperationBinding); myBinding.Extensions.Add(mySoapBinding); // Add the Binding to the ServiceDescription. myDescription.Bindings.Add(myBinding); myDescription.Write("MyOutWsdl.wsdl"); // </Snippet1> } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
static void Main() { try { // Get a DiscoveryDocument. DiscoveryDocument myDiscoveryDocument = new DiscoveryDocument(); // Get a ContractReference. ContractReference myContractReference = new ContractReference(); // Set the URL to the referenced service description. myContractReference.Ref = "http://localhost/service1.asmx?wsdl"; // Set the URL for an XML Web service implementing the service // description. myContractReference.DocRef = "http://localhost/service1.asmx"; SoapBinding myBinding = new SoapBinding(); myBinding.Binding = new XmlQualifiedName("q1:Service1Soap"); myBinding.Address = "http://localhost/service1.asmx"; // Add myContractReference to the list of references contained // in the discovery document. myDiscoveryDocument.References.Add(myContractReference); // Add Binding to the references collection. myDiscoveryDocument.References.Add(myBinding); // Open or create a file for writing. FileStream myFileStream = new FileStream("Service1.disco", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter myStreamWriter = new StreamWriter(myFileStream); // Write myDiscoveryDocument into the passed stream. myDiscoveryDocument.Write(myStreamWriter); Console.WriteLine("The Service1.disco is generated."); } catch (Exception e) { Console.WriteLine("Error is " + e.Message); } }
public void ExportEndpointTest5() { WsdlExporter we = new WsdlExporter(); ServiceEndpoint se = new ServiceEndpoint(ContractDescription.GetContract(typeof(IEchoService))); se.Binding = new BasicHttpBinding(); se.Address = new EndpointAddress("http://localhost:8080"); we.ExportEndpoint(se); MetadataSet ms = we.GetGeneratedMetadata(); Assert.AreEqual(6, ms.MetadataSections.Count); WSServiceDescription wsd = GetServiceDescription(ms, "http://tempuri.org/", "ExportEndpointTest5#1"); SoapBinding soapBinding = (SoapBinding)wsd.Bindings [0].Extensions [0]; Assert.AreEqual(SoapBindingStyle.Document, soapBinding.Style, "soapBinding.Style"); Assert.AreEqual(SoapBinding.HttpTransport, soapBinding.Transport, "soapBinding.Transport"); }
void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context) { for (int i = 0; i < context.WsdlBinding.Extensions.Count; i++) { if (context.WsdlBinding.Extensions [i] is SoapBinding) { SoapBinding transport = context.WsdlBinding.Extensions [i] as SoapBinding; if (transport.Transport != SoapBinding.HttpTransport) { //FIXME: not http return; } if (!(context.Endpoint.Binding is CustomBinding)) { //FIXME: throw new Exception(); } ((CustomBinding)context.Endpoint.Binding).Elements.Add(new HttpTransportBindingElement()); //((CustomBinding) context.Endpoint.Binding).Scheme = "http"; for (int j = 0; j < context.WsdlPort.Extensions.Count; j++) { SoapAddressBinding address = context.WsdlPort.Extensions [j] as SoapAddressBinding; if (address == null) { continue; } context.Endpoint.Address = new EndpointAddress(address.Location); context.Endpoint.ListenUri = new Uri(address.Location); } break; } } }
static void Run() { try { // dataservice.disco is a sample discovery document. string myStringUrl = "http://localhost/dataservice.disco"; // Call the Discover method to populate the Documents property. DiscoveryClientProtocol myDiscoveryClientProtocol = new DiscoveryClientProtocol(); myDiscoveryClientProtocol.Credentials = CredentialCache.DefaultCredentials; DiscoveryDocument myDiscoveryDocument = myDiscoveryClientProtocol.Discover(myStringUrl); SoapBinding mySoapBinding = new SoapBinding(); mySoapBinding.Address = "http://schemas.xmlsoap.org/disco/scl/"; mySoapBinding.Binding = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); myDiscoveryClientProtocol.AdditionalInformation.Add(mySoapBinding); // Write the information back. myDiscoveryClientProtocol.WriteAll("MyDirectory", "results.discomap"); System.Collections.IList myIList = myDiscoveryClientProtocol.AdditionalInformation; mySoapBinding = null; mySoapBinding = (SoapBinding)myIList[0]; Console.WriteLine("The address of the SoapBinding associated " + "with AdditionalInformation is: " + mySoapBinding.Address); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
internal static void ExportWsdlEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext, string wsdlTransportUri, AddressingVersion addressingVersion) { if (exporter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (endpointContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext"); } endpointContext.Endpoint.Binding.CreateBindingElements(); if (wsdlTransportUri != null) { SoapBinding orCreateSoapBinding = SoapHelper.GetOrCreateSoapBinding(endpointContext, exporter); if (orCreateSoapBinding != null) { orCreateSoapBinding.Transport = wsdlTransportUri; } } if (endpointContext.WsdlPort != null) { WsdlExporter.WSAddressingHelper.AddAddressToWsdlPort(endpointContext.WsdlPort, endpointContext.Endpoint.Address, addressingVersion); } }
// <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); } }
void ExportEndpoint(ServiceEndpoint endpoint, bool rejectDuplicate) { List <IWsdlExportExtension> extensions = ExportContractInternal(endpoint.Contract, rejectDuplicate); //FIXME: Namespace WSServiceDescription sd = GetServiceDescription("http://tempuri.org/"); if (sd.TargetNamespace != endpoint.Contract.Namespace) { sd.Namespaces.Add("i0", endpoint.Contract.Namespace); //Import Import import = new Import(); import.Namespace = endpoint.Contract.Namespace; sd.Imports.Add(import); } if (endpoint.Binding == null) { throw new ArgumentException(String.Format( "Binding for ServiceEndpoint named '{0}' is null", endpoint.Name)); } bool msg_version_none = endpoint.Binding.MessageVersion != null && endpoint.Binding.MessageVersion.Equals(MessageVersion.None); //ExportBinding WSBinding ws_binding = new WSBinding(); //<binding name = .. ws_binding.Name = String.Concat(endpoint.Binding.Name, "_", endpoint.Contract.Name); //<binding type = .. ws_binding.Type = new QName(endpoint.Contract.Name, endpoint.Contract.Namespace); sd.Bindings.Add(ws_binding); if (!msg_version_none) { SoapBinding soap_binding = new SoapBinding(); soap_binding.Transport = SoapBinding.HttpTransport; soap_binding.Style = SoapBindingStyle.Document; ws_binding.Extensions.Add(soap_binding); } // <operation foreach (OperationDescription sm_op in endpoint.Contract.Operations) { OperationBinding op_binding = new OperationBinding(); op_binding.Name = sm_op.Name; //FIXME: Move to IWsdlExportExtension .. ? foreach (MessageDescription sm_md in sm_op.Messages) { if (sm_md.Direction == MessageDirection.Input) { //<input InputBinding in_binding = new InputBinding(); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding(); soap_body_binding.Use = SoapBindingUse.Literal; in_binding.Extensions.Add(soap_body_binding); //Set Action //<operation > <soap:operation soapAction .. > SoapOperationBinding soap_operation_binding = new SoapOperationBinding(); soap_operation_binding.SoapAction = sm_md.Action; soap_operation_binding.Style = SoapBindingStyle.Document; op_binding.Extensions.Add(soap_operation_binding); } op_binding.Input = in_binding; } else { //<output OutputBinding out_binding = new OutputBinding(); if (!msg_version_none) { SoapBodyBinding soap_body_binding = new SoapBodyBinding(); soap_body_binding.Use = SoapBindingUse.Literal; out_binding.Extensions.Add(soap_body_binding); } op_binding.Output = out_binding; } } ws_binding.Operations.Add(op_binding); } //Add <service Port ws_port = ExportService(sd, ws_binding, endpoint.Address, msg_version_none); //Call IWsdlExportExtension.ExportEndpoint WsdlContractConversionContext contract_context = new WsdlContractConversionContext( endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]); WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext( contract_context, endpoint, ws_port, ws_binding); if (extensions != null) { foreach (IWsdlExportExtension extn in extensions) { extn.ExportEndpoint(this, endpoint_context); } } }
public static void Main() { // <Snippet9> ServiceDescription myServiceDescription = ServiceDescription.Read("MathService_input_cs.wsdl"); // Create SOAP messages. // <Snippet7> Message myMessage = new Message(); myMessage.Name = "AddSoapOut"; // <Snippet14> MessagePart myMessagePart = new MessagePart(); myMessagePart.Name = "parameters"; myMessagePart.Element = new XmlQualifiedName("AddResponse", myServiceDescription.TargetNamespace); myMessage.Parts.Add(myMessagePart); // </Snippet14> myServiceDescription.Messages.Add(myMessage); // </Snippet9> // </Snippet7> // <Snippet8> Message myMessage1 = new Message(); myMessage1.Name = "AddSoapIn"; // <Snippet15> MessagePart myMessagePart1 = new MessagePart(); myMessagePart1.Name = "parameters"; myMessagePart1.Element = new XmlQualifiedName("Add", myServiceDescription.TargetNamespace); myMessage1.Parts.Insert(0, myMessagePart1); // </Snippet15> myServiceDescription.Messages.Insert(16, myMessage1); // </Snippet8> myServiceDescription.Messages.Add( CreateMessage("SubtractSoapIn", "parameters", "Subtract", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add( CreateMessage("SubtractSoapOut", "parameters", "SubtractResponse", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add( CreateMessage("MultiplySoapIn", "parameters", "Multiply", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add( CreateMessage("MultiplySoapOut", "parameters", "MultiplyResponse", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add( CreateMessage("DivideSoapIn", "parameters", "Divide", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add( CreateMessage("DivideSoapOut", "parameters", "DivideResponse", myServiceDescription.TargetNamespace)); // Create a new PortType. PortType soapPortType = new PortType(); soapPortType.Name = "MathServiceSoap"; soapPortType.Operations.Add(CreateOperation("Add", "AddSoapIn", "AddSoapOut", myServiceDescription.TargetNamespace)); soapPortType.Operations.Add(CreateOperation("Subtract", "SubtractSoapIn", "SubtractSoapOut", myServiceDescription.TargetNamespace)); soapPortType.Operations.Add(CreateOperation("Multiply", "MultiplySoapIn", "MultiplySoapOut", myServiceDescription.TargetNamespace)); soapPortType.Operations.Add(CreateOperation("Divide", "DivideSoapIn", "DivideSoapOut", myServiceDescription.TargetNamespace)); myServiceDescription.PortTypes.Add(soapPortType); // Create a new Binding for the SOAP protocol. Binding myBinding = new Binding(); myBinding.Name = myServiceDescription.Services[0].Name + "Soap"; // Pass the name of the existing PortType MathServiceSoap and the // Xml TargetNamespace attribute of the Descriptions tag. myBinding.Type = new XmlQualifiedName("MathServiceSoap", myServiceDescription.TargetNamespace); // Create a SOAP extensibility element. SoapBinding mySoapBinding = new SoapBinding(); mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http"; mySoapBinding.Style = SoapBindingStyle.Document; // Add tag soap:binding as an extensibility element. myBinding.Extensions.Add(mySoapBinding); // Create OperationBindings for each of the operations defined // in the .asmx file. OperationBinding addOperationBinding = CreateOperationBinding( "Add", myServiceDescription.TargetNamespace); myBinding.Operations.Add(addOperationBinding); OperationBinding subtractOperationBinding = CreateOperationBinding( "Subtract", myServiceDescription.TargetNamespace); myBinding.Operations.Add(subtractOperationBinding); OperationBinding multiplyOperationBinding = CreateOperationBinding( "Multiply", myServiceDescription.TargetNamespace); myBinding.Operations.Add(multiplyOperationBinding); OperationBinding divideOperationBinding = CreateOperationBinding( "Divide", myServiceDescription.TargetNamespace); myBinding.Operations.Add(divideOperationBinding); myServiceDescription.Bindings.Insert(0, myBinding); Console.WriteLine("\nTarget namespace of the service description to " + "which the binding was added is: " + myServiceDescription.Bindings[0].ServiceDescription.TargetNamespace); // Create a Port. Port soapPort = new Port(); soapPort.Name = "MathServiceSoap"; soapPort.Binding = new XmlQualifiedName(myBinding.Name, myServiceDescription.TargetNamespace); // Create a SoapAddress extensibility element to add to the port. SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding(); mySoapAddressBinding.Location = "http://localhost/MathService.cs.asmx"; soapPort.Extensions.Add(mySoapAddressBinding); // Add the port to the MathService, which is the first service in // the service collection. myServiceDescription.Services[0].Ports.Add(soapPort); // Save the ServiceDescripition to an external file. myServiceDescription.Write("MathService_new.wsdl"); Console.WriteLine("\nSuccessfully added bindings for SOAP protocol " + "and saved results in the file MathService_new.wsdl"); Console.WriteLine("\n This file should be passed to the WSDL tool " + "as input to generate the proxy"); }
public static void Main() { ServiceDescription myServiceDescription = ServiceDescription.Read("MathService_input.wsdl"); // Create SOAP Messages. myServiceDescription.Messages.Add(CreateMessage("AddSoapIn", "parameters", "Add", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add(CreateMessage("AddSoapOut", "parameters", "AddResponse", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add(CreateMessage("SubtractSoapIn", "parameters", "Subtract", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add(CreateMessage("SubtractSoapOut", "parameters", "SubtractResponse", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add(CreateMessage("MultiplySoapIn", "parameters", "Multiply", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add(CreateMessage("MultiplySoapOut", "parameters", "MultiplyResponse", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add(CreateMessage("DivideSoapIn", "parameters", "Divide", myServiceDescription.TargetNamespace)); myServiceDescription.Messages.Add(CreateMessage("DivideSoapOut", "parameters", "DivideResponse", myServiceDescription.TargetNamespace)); // Create a new PortType. PortType soapPortType = new PortType(); soapPortType.Name = "MathServiceSoap"; soapPortType.Operations.Add(CreateOperation("Add", "AddSoapIn", "AddSoapOut", myServiceDescription.TargetNamespace)); soapPortType.Operations.Add(CreateOperation("Subtract", "SubtractSoapIn", "SubtractSoapOut", myServiceDescription.TargetNamespace)); soapPortType.Operations.Add(CreateOperation("Multiply", "MultiplySoapIn", "MultiplySoapOut", myServiceDescription.TargetNamespace)); soapPortType.Operations.Add(CreateOperation("Divide", "DivideSoapIn", "DivideSoapOut", myServiceDescription.TargetNamespace)); myServiceDescription.PortTypes.Add(soapPortType); // <Snippet2> // <Snippet1> // <Snippet6> // Create a new Binding for SOAP Protocol. Binding myBinding = new Binding(); myBinding.Name = myServiceDescription.Services[0].Name + "Soap"; // </Snippet2> // <Snippet3> // Pass the name of the existing porttype 'MathServiceSoap' and the Xml targetNamespace attribute of the Descriptions tag. myBinding.Type = new XmlQualifiedName("MathServiceSoap", myServiceDescription.TargetNamespace); // </Snippet3> // <Snippet4> // Create SOAP Extensibility element. SoapBinding mySoapBinding = new SoapBinding(); // SOAP over HTTP. mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http"; mySoapBinding.Style = SoapBindingStyle.Document; // Add tag soap:binding as an extensibility element. myBinding.Extensions.Add(mySoapBinding); // </Snippet4> // <Snippet5> // Create OperationBindings for each of the operations defined in asmx file. OperationBinding addOperationBinding = CreateOperationBinding("Add", myServiceDescription.TargetNamespace); myBinding.Operations.Add(addOperationBinding); OperationBinding subtractOperationBinding = CreateOperationBinding("Subtract", myServiceDescription.TargetNamespace); myBinding.Operations.Add(subtractOperationBinding); OperationBinding multiplyOperationBinding = CreateOperationBinding("Multiply", myServiceDescription.TargetNamespace); myBinding.Operations.Add(multiplyOperationBinding); OperationBinding divideOperationBinding = CreateOperationBinding("Divide", myServiceDescription.TargetNamespace); myBinding.Operations.Add(divideOperationBinding); // </Snippet5> myServiceDescription.Bindings.Insert(0, myBinding); // </Snippet1> // </Snippet6> // <Snippet7> Console.WriteLine("\nTarget Namespace of the Service Description to which the binding was added is:" + myServiceDescription.Bindings[0].ServiceDescription.TargetNamespace); // </Snippet7> // Create Port. Port soapPort = new Port(); soapPort.Name = "MathServiceSoap"; soapPort.Binding = new XmlQualifiedName(myBinding.Name, myServiceDescription.TargetNamespace); // Create SoapAddress extensibility element to add to port. SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding(); mySoapAddressBinding.Location = "http://localhost/BindingCollectionSample/MathService.asmx"; soapPort.Extensions.Add(mySoapAddressBinding); // Add port to the MathService which is the first service in the Service Collection. myServiceDescription.Services[0].Ports.Add(soapPort); // Save the ServiceDescripition instance to an external file. myServiceDescription.Write("MathService_new.wsdl"); Console.WriteLine("\nSuccessfully added bindings for SOAP protocol and saved results in file MathService_new.wsdl"); Console.WriteLine("\n This file should be passed to wsdl tool as input to generate proxy"); }
public static void Main() { ServiceDescription myServiceDescription = ServiceDescription.Read("SoapBindingStyleInput_cs.wsdl"); Binding myBinding = new Binding(); myBinding.Name = "SOAPSvrMgr_SOAPBinding"; myBinding.Type = new XmlQualifiedName("tns:SOAPSvrMgr_portType"); // <Snippet1> SoapBinding mySoapBinding = new SoapBinding(); mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http"; // Message to be transmitted contains parameters to call a procedure. mySoapBinding.Style = SoapBindingStyle.Rpc; myBinding.Extensions.Add(mySoapBinding); // </Snippet1> OperationBinding myOperationBinding = new OperationBinding(); myOperationBinding.Name = "GetServerStats"; SoapOperationBinding mySoapOperationBinding = new SoapOperationBinding(); mySoapOperationBinding.SoapAction = "http://tempuri.org/soapsvcmgr/GetServerStats"; myOperationBinding.Extensions.Add(mySoapOperationBinding); // Create InputBinding for operation for the 'SOAP' protocol. InputBinding myInputBinding = new InputBinding(); // <Snippet2> // <Snippet3> // <Snippet4> SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding(); // Encode SOAP body using rules specified by the 'Encoding' property. mySoapBodyBinding.Use = SoapBindingUse.Encoded; // Set URI representing the encoding style for encoding the body. mySoapBodyBinding.Encoding = "http://schemas.xmlsoap.org/soap/encoding/"; // Set the Uri representing the location of the specification // for encoding of content not defined by 'Encoding' property'. mySoapBodyBinding.Namespace = "http://tempuri.org/soapsvcmgr/"; myInputBinding.Extensions.Add(mySoapBodyBinding); // </Snippet4> // </Snippet3> // </Snippet2> // <Snippet5> // <Snippet6> SoapHeaderBinding mySoapHeaderBinding = new SoapHeaderBinding(); mySoapHeaderBinding.Message = new XmlQualifiedName("tns:Soapsvcmgr_Headers_Request"); mySoapHeaderBinding.Part = "AuthCS"; // Encode SOAP header using rules specified by the 'Encoding' property. mySoapHeaderBinding.Use = SoapBindingUse.Encoded; // Set URI representing the encoding style for encoding the header. mySoapHeaderBinding.Encoding = "http://schemas.xmlsoap.org/soap/encoding/"; // Set the Uri representing the location of the specification // for encoding of content not defined by 'Encoding' property'. mySoapHeaderBinding.Namespace = "http://tempuri.org/SOAPSvr/soapsvcmgr/headers.xsd"; // Add mySoapHeaderBinding to the 'myInputBinding' object. myInputBinding.Extensions.Add(mySoapHeaderBinding); // </Snippet5> // </Snippet6> // Create OutputBinding for operation. OutputBinding myOutputBinding = new OutputBinding(); myOutputBinding.Extensions.Add(mySoapBodyBinding); mySoapHeaderBinding.Part = "AuthSC"; mySoapHeaderBinding.Message = new XmlQualifiedName("tns:Soapsvcmgr_Headers_Response"); myOutputBinding.Extensions.Add(mySoapHeaderBinding); // Add 'InputBinding' and 'OutputBinding' to 'OperationBinding'. myOperationBinding.Input = myInputBinding; myOperationBinding.Output = myOutputBinding; myBinding.Operations.Add(myOperationBinding); myServiceDescription.Bindings.Add(myBinding); myServiceDescription.Write("SoapBindingStyleOutput_cs.wsdl"); Console.WriteLine("'SoapBindingStyleOutput_cs.wsdl' file is generated."); Console.WriteLine("Proxy could be created using command" + " 'wsdl SoapBindingStyleOutput_cs.wsdl'"); }
public static void Main() { ServiceDescription myDescription = ServiceDescription.Read("AddNumbersInput_cs.wsdl"); // Create a 'Binding' object for the 'SOAP' protocol. Binding myBinding = new Binding(); myBinding.Name = "Service1Soap"; XmlQualifiedName qualifiedName = new XmlQualifiedName("s0:Service1Soap"); myBinding.Type = qualifiedName; // <Snippet5> SoapBinding mySoapBinding = new SoapBinding(); mySoapBinding.Transport = SoapBinding.HttpTransport; mySoapBinding.Style = SoapBindingStyle.Document; // </Snippet5> // Add the 'SoapBinding' object to the 'Binding' object. myBinding.Extensions.Add(mySoapBinding); // Create the 'OperationBinding' object for the 'SOAP' protocol. OperationBinding myOperationBinding = new OperationBinding(); myOperationBinding.Name = "AddNumbers"; // Create the 'SoapOperationBinding' object for the 'SOAP' protocol. SoapOperationBinding mySoapOperationBinding = new SoapOperationBinding(); mySoapOperationBinding.SoapAction = "http://tempuri.org/AddNumbers"; mySoapOperationBinding.Style = SoapBindingStyle.Document; // Add the 'SoapOperationBinding' object to 'OperationBinding' object. myOperationBinding.Extensions.Add(mySoapOperationBinding); // Create the 'InputBinding' object for the 'SOAP' protocol. InputBinding myInput = new InputBinding(); SoapBodyBinding mySoapBinding1 = new SoapBodyBinding(); mySoapBinding1.Use = SoapBindingUse.Literal; myInput.Extensions.Add(mySoapBinding1); // Assign the 'InputBinding' to 'OperationBinding'. myOperationBinding.Input = myInput; // Create the 'OutputBinding' object' for the 'SOAP' protocol.. OutputBinding myOutput = new OutputBinding(); myOutput.Extensions.Add(mySoapBinding1); // Assign 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); Port soapPort = new Port(); soapPort.Name = "Service1Soap"; soapPort.Binding = new XmlQualifiedName("s0:Service1Soap"); // Create a 'SoapAddressBinding' object for the 'SOAP' protocol. SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding(); mySoapAddressBinding.Location = "http://localhost/AddNumbers.cs.asmx"; // Add the 'SoapAddressBinding' to the 'Port'. soapPort.Extensions.Add(mySoapAddressBinding); // Add the 'Port' to 'PortCollection' of 'ServiceDescription'. myDescription.Services[0].Ports.Add(soapPort); // Write the 'ServiceDescription' as a WSDL file. myDescription.Write("AddNumbersOut_cs.wsdl"); Console.WriteLine(" 'AddNumbersOut_cs.Wsdl' file was generated"); }
/// <summary> /// Validates a specified instance of <see cref="ServiceDescription"/> class for the round tripping feature. /// </summary> /// <param name="serviceDescription"> /// An instance of <see cref="ServiceDescription"/> class to /// validate. /// </param> /// <param name="isHttpBinding">A reference to a Boolean variable. Value is this variable is set to true if the service description has Http binding.</param> /// <returns> /// A value indicating whether the specified instance of <see cref="ServiceDescription"/> /// class is valid for the round tripping feature. /// </returns> private static bool ValidateWsdl( System.Web.Services.Description.ServiceDescription serviceDescription, ref bool isHttpBinding) { // Rule No 1: Service description must have atleast one schema in the types definitions. if (serviceDescription.Types.Schemas.Count == 0) { return(false); } // Rule No 2: Service description must have only one <porttype>. if (serviceDescription.PortTypes.Count != 1) { return(false); } // Rule No 3: Service description must have only SOAP 1.1 and/or SOAP 1.2 binding(s). if (!((serviceDescription.Bindings.Count == 1 && serviceDescription.Bindings[0].Extensions.Find(typeof(SoapBinding)) != null) || (serviceDescription.Bindings.Count == 2 && serviceDescription.Bindings[0].Extensions.Find(typeof(SoapBinding)) != null && serviceDescription.Bindings[1].Extensions.Find(typeof(Soap12Binding)) != null))) { return(false); } // Rule No 4: Service description can not have more than one <service>. But it is possible // not to have a <service>. if (serviceDescription.Services.Count > 1) { return(false); } // Rule No 5: Each message must have only one <part>. foreach (FxMessage message in serviceDescription.Messages) { if (message.Parts.Count > 1) { return(false); } } // Rule No 6: For soap bindings the binding style must be 'Document' and encoding must be 'Literal'. // Obtain a reference to the one and only binding we have. System.Web.Services.Description.Binding binding = serviceDescription.Bindings[0]; // Search for the soap binding style and return false if it is not 'Document' foreach (ServiceDescriptionFormatExtension extension in binding.Extensions) { SoapBinding soapBinding = extension as SoapBinding; if (soapBinding != null) { if (soapBinding.Style != SoapBindingStyle.Document) { return(false); } } else if (extension is HttpBinding) { isHttpBinding = true; } } // Validate the operation bindings. foreach (OperationBinding operationBinding in binding.Operations) { // Validate the soap binding style in soap operation binding extension. foreach (ServiceDescriptionFormatExtension extension in operationBinding.Extensions) { SoapOperationBinding soapOperationBinding = extension as SoapOperationBinding; if (soapOperationBinding != null) { if (soapOperationBinding.Style != SoapBindingStyle.Document) { return(false); } } } // Validate the 'use' element in input message body and the headers. foreach (ServiceDescriptionFormatExtension extension in operationBinding.Input.Extensions) { // Check for a header. SoapHeaderBinding headerBinding = extension as SoapHeaderBinding; if (headerBinding != null) { if (headerBinding.Use != SoapBindingUse.Literal) { return(false); } continue; } // Check for the body. SoapBodyBinding bodyBinding = extension as SoapBodyBinding; if (bodyBinding != null) { if (bodyBinding.Use != SoapBindingUse.Literal) { return(false); } continue; } } // Validate the 'use' element in output message body and the headers. if (operationBinding.Output != null) { foreach (ServiceDescriptionFormatExtension extension in operationBinding.Output.Extensions) { // Check for the header. SoapHeaderBinding headerBinding = extension as SoapHeaderBinding; if (headerBinding != null) { if (headerBinding.Use != SoapBindingUse.Literal) { return(false); } continue; } // Check for the body. SoapBodyBinding bodyBinding = extension as SoapBodyBinding; if (bodyBinding != null) { if (bodyBinding.Use != SoapBindingUse.Literal) { return(false); } continue; } } } } return(true); }