Esempio n. 1
0
        public string GenerateHttpSoapMessage(Port port, OperationBinding obin, Operation oper, OperationMessage msg)
        {
            string req = "";

            if (msg is OperationInput)
            {
                SoapAddressBinding   sab = port.Extensions.Find(typeof(SoapAddressBinding)) as SoapAddressBinding;
                SoapOperationBinding sob = obin.Extensions.Find(typeof(SoapOperationBinding)) as SoapOperationBinding;

                req += "POST " + GetAbsolutePath(sab.Location) + "\n";
                req += "SOAPAction: " + sob.SoapAction + "\n";
                req += "Content-Type: text/xml; charset=utf-8\n";
                req += "Content-Length: " + GetLiteral("string") + "\n";
                req += "Host: " + GetLiteral("string") + "\n\n";
            }
            else
            {
                req += "HTTP/1.0 200 OK\n";
                req += "Content-Type: text/xml; charset=utf-8\n";
                req += "Content-Length: " + GetLiteral("string") + "\n\n";
            }

            req += GenerateSoapMessage(obin, oper, msg);
            return(req);
        }
Esempio n. 2
0
            internal static bool ConvertSoapAddressBinding(ref object src, EnvelopeVersion version)
            {
                SoapAddressBinding binding = src as SoapAddressBinding;

                if (src != null)
                {
                    if (binding == null)
                    {
                        return(false);
                    }
                    if (GetBindingVersion <Soap12AddressBinding>(src) == version)
                    {
                        return(true);
                    }
                }
                if (version == EnvelopeVersion.None)
                {
                    src = null;
                    return(true);
                }
                SoapAddressBinding binding2 = (version == EnvelopeVersion.Soap12) ? new Soap12AddressBinding() : new SoapAddressBinding();

                if (binding != null)
                {
                    binding2.Required = binding.Required;
                    binding2.Location = binding.Location;
                }
                src = binding2;
                return(true);
            }
Esempio n. 3
0
        public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            var scheme = HttpContext.Current.Request.Headers["X-Forwarded-Proto"] ?? HttpContext.Current.Request.Url.Scheme;
            var host   = HttpContext.Current.Request.Url.Host;

            _location = new Uri($"{scheme}://{host}");

            foreach (object extension in context.WsdlPort.Extensions)
            {
                SoapAddressBinding addr = (extension as SoapAddressBinding);
                if (addr != null)
                {
                    addr.Location = Rewrite(addr.Location).ToString();
                }
            }

            EnumerateWsdlsAndSchemas(exporter.GeneratedWsdlDocuments, exporter.GeneratedXmlSchemas);

            foreach (ServiceDescription description in exporter.GeneratedWsdlDocuments)
            {
                FixImportAddresses(exporter.GeneratedWsdlDocuments, description, exporter.GeneratedXmlSchemas);
            }
            foreach (XmlSchema schema in exporter.GeneratedXmlSchemas.Schemas())
            {
                FixImportAddresses(exporter.GeneratedXmlSchemas, schema);
            }
        }
        Port ExportService(WSServiceDescription sd, WSBinding ws_binding, EndpointAddress address, bool msg_version_none)
        {
            if (address == null)
            {
                return(null);
            }

            Service ws_svc = GetService(sd, "service");

            sd.Name = "service";

            Port ws_port = new Port();

            ws_port.Name    = ws_binding.Name;
            ws_port.Binding = new QName(ws_binding.Name, sd.TargetNamespace);

            if (!msg_version_none)
            {
                SoapAddressBinding soap_addr = new SoapAddressBinding();
                soap_addr.Location = address.Uri.AbsoluteUri;

                ws_port.Extensions.Add(soap_addr);
            }

            ws_svc.Ports.Add(ws_port);

            return(ws_port);
        }
        private static void ImportAddress(WsdlEndpointConversionContext context)
        {
            EndpointAddress endpointAddress = null;

            if (context.WsdlPort != null)
            {
                XmlElement         xmlElement         = context.WsdlPort.Extensions.Find("EndpointReference", "http://www.w3.org/2005/08/addressing");
                XmlElement         xmlElement1        = context.WsdlPort.Extensions.Find("EndpointReference", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
                SoapAddressBinding soapAddressBinding = (SoapAddressBinding)context.WsdlPort.Extensions.Find(typeof(SoapAddressBinding));
                if (xmlElement != null)
                {
                    endpointAddress = EndpointAddress.ReadFrom(AddressingVersion.WSAddressing10, new XmlNodeReader(xmlElement));
                }
                if (xmlElement1 != null)
                {
                    endpointAddress = EndpointAddress.ReadFrom(AddressingVersion.WSAddressingAugust2004, new XmlNodeReader(xmlElement1));
                }
                else if (soapAddressBinding != null)
                {
                    endpointAddress = new EndpointAddress(soapAddressBinding.Location);
                }
            }
            if (endpointAddress != null)
            {
                context.Endpoint.Address = endpointAddress;
            }
        }
Esempio n. 6
0
 void RewriteSoapAddressBinding(SoapAddressBinding addressBinding)
 {
     if (addressBinding.Location != null)
     {
         addressBinding.Location = RewriteAddress(addressBinding.Location);
     }
 }
Esempio n. 7
0
        private void ConvertService(DescriptionType wsdl2, ServiceDescription wsdl1)
        {
            var services = wsdl2.Items.Where(s => s is ServiceType);

            foreach (ServiceType s2 in services)
            {
                var s1 = new Service();
                wsdl1.Services.Add(s1);
                s1.Name = s2.name;

                foreach (EndpointType e2 in s2.Items)
                {
                    var p1 = new Port();
                    s1.Ports.Add(p1);

                    p1.Name    = e2.name;
                    p1.Binding = e2.binding;

                    var sab = new SoapAddressBinding()
                    {
                        Location = e2.address
                    };
                    var sab12 = new Soap12AddressBinding()
                    {
                        Location = e2.address
                    };
                    p1.Extensions.Add(sab);
                    p1.Extensions.Add(sab12);
                }
            }
        }
Esempio n. 8
0
        void GenerateDiscoDocument(HttpContext context)
        {
            ServiceDescriptionCollection descs = GetDescriptions();

            DiscoveryDocument doc  = new DiscoveryDocument();
            ContractReference cref = new ContractReference();

            cref.Ref    = _url + "?wsdl";
            cref.DocRef = _url;
            doc.References.Add(cref);

            foreach (ServiceDescription desc in descs)
            {
                foreach (Service ser in desc.Services)
                {
                    foreach (Port port in ser.Ports)
                    {
                        SoapAddressBinding sab = port.Extensions.Find(typeof(SoapAddressBinding)) as SoapAddressBinding;
                        if (sab != null)
                        {
                            System.Web.Services.Discovery.SoapBinding dsb = new System.Web.Services.Discovery.SoapBinding();
                            dsb.Address = sab.Location;
                            dsb.Binding = port.Binding;
                            doc.AdditionalInfo.Add(dsb);
                        }
                    }
                }
            }

            context.Response.ContentType = "text/xml; charset=utf-8";
            XmlTextWriter xtw = new XmlTextWriter(context.Response.OutputStream, new UTF8Encoding(false));

            xtw.Formatting = Formatting.Indented;
            doc.Write(xtw);
        }
Esempio n. 9
0
	public void Parse()
	{			
	foreach (Service service in _services[0].Services )
	{
	TreeNode tnService=new TreeNode(service.Name) ;
	tnService.ImageIndex=1;
	tnService.SelectedImageIndex=1;

	foreach (Port port in service.Ports)
	{
	XmlQualifiedName bindName=port.Binding ;
	Binding bind=_services.GetBinding(bindName);			
	PortType portType=_services.GetPortType(bind.Type) ;
       TreeNode tnPort=new TreeNode (port.Name);
	tnPort.ImageIndex=6;
	tnPort.SelectedImageIndex=6;
	string protocol=GetProtocol (bind);
	string portDesc="Protocol: " + protocol + "\n";
      	switch (protocol) 
	{
	case "Soap":
	{
	SoapAddressBinding ad=(SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
	portDesc += "Location: " + ad.Location + "\n";
	break;
	 }
	 case "HttpGet":
	{
	HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
	portDesc += "Location: " + ad.Location + "\n";
break;
	case "HttpPost":
	{
	HttpAddressBinding ad=(HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
portDesc += "Location: "   + ad.Location + "\n";
break;
}
}
tnPort.Tag=portDesc;
foreach (OperationBinding obin in bind.Operations)					
{									
foreach (Operation oper in portType.Operations)
if (obin.Name.Equals(oper.Name) )
{
TreeNode tnOper=TranslateOperation (port, obin, oper, protocol);										
tnOper.ImageIndex=11;
tnOper.SelectedImageIndex=11;
if (tnOper != null)
{
tnPort.Nodes.Add (tnOper);	};
}												
}
tnPort.Expand ();					
tnService.Nodes.Add(tnPort) ;
}
ServiceNode.Nodes.Add (tnService);					
}
}		
        /// <summary>
        /// Is the given port an ASMX endpoint with the given SOAP address type?
        /// </summary>
        /// <param name="addressType"></param>
        /// <param name="port"></param>
        /// <returns></returns>
        private bool IsSoapAsmxPort(System.Type addressType, Port port)
        {
            SoapAddressBinding addressBinding = port.Extensions.Find(addressType) as SoapAddressBinding;

            if (addressBinding != null && addressBinding.GetType() == addressType && IsAsmxUri(addressBinding.Location))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        void CheckServicePort(Service svc, string port_name, XmlQualifiedName binding_name, string address, string label)
        {
            Port port = svc.Ports [port_name];

            Assert.IsNotNull(port, label + " #csp0");
            Assert.AreEqual(port.Binding, binding_name, label + " #csp1");

            Assert.AreEqual(1, port.Extensions.Count, label + " #csp2");
            Assert.AreEqual(typeof(SoapAddressBinding), port.Extensions [0].GetType(), label + " #csp3");
            SoapAddressBinding sab = (SoapAddressBinding)port.Extensions [0];

            Assert.AreEqual(address, sab.Location, label + " #csp3");
        }
Esempio n. 12
0
        private static SoapAddressBinding CreateSoapAddressBinding(EnvelopeVersion version, Port wsdlPort)
        {
            SoapAddressBinding extension = null;

            if (version == EnvelopeVersion.Soap12)
            {
                extension = new Soap12AddressBinding();
            }
            else if (version == EnvelopeVersion.Soap11)
            {
                extension = new SoapAddressBinding();
            }
            wsdlPort.Extensions.Add(extension);
            return(extension);
        }
Esempio n. 13
0
 static string GetLocation(ServiceDescription doc)
 {
     foreach (Service s in doc.Services)
     {
         foreach (Port p in s.Ports)
         {
             SoapAddressBinding loc = (SoapAddressBinding)p.Extensions.Find(typeof(System.Web.Services.Description.SoapAddressBinding));
             if (loc != null)
             {
                 return(loc.Location);
             }
         }
     }
     return(null);
 }
Esempio n. 14
0
        internal static SoapAddressBinding GetOrCreateSoapAddressBinding(Binding wsdlBinding, Port wsdlPort, WsdlExporter exporter)
        {
            if (GetSoapVersionState(wsdlBinding, exporter) == EnvelopeVersion.None)
            {
                return(null);
            }
            SoapAddressBinding soapAddressBinding = GetSoapAddressBinding(wsdlPort);
            EnvelopeVersion    soapVersion        = GetSoapVersion(wsdlBinding);

            if (soapAddressBinding != null)
            {
                return(soapAddressBinding);
            }
            return(CreateSoapAddressBinding(soapVersion, wsdlPort));
        }
Esempio n. 15
0
    public static Port CreatePort(string PortName, string BindingName,
                                  string targetNamespace)
    {
        Port myPort = new Port();

        myPort.Name    = PortName;
        myPort.Binding = new XmlQualifiedName(BindingName, targetNamespace);

        // Create a SoapAddress extensibility element to add to the port.
        SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();

        mySoapAddressBinding.Location =
            "http://localhost/ServiceClass/MathService_CS.asmx";
        myPort.Extensions.Add(mySoapAddressBinding);
        return(myPort);
    }
Esempio n. 16
0
 /// <summary>
 /// Search and returns the url for the specified binding.
 /// </summary>
 private string GetWsUrl(ServiceDescriptionCollection serviceDescriptions, Binding binding)
 {
     foreach (ServiceDescription description in serviceDescriptions)
     {
         foreach (Service service in description.Services)
         {
             foreach (Port port in service.Ports)
             {
                 if (port.Binding.Name == binding.Name)
                 {
                     SoapAddressBinding soapAddress = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
                     return(soapAddress.Location);
                 }
             }
         }
     }
     throw new ApplicationException(String.Format("No SoapAddressBinding has been found for binding '{0}' in the WSDL document located at '{1}'.", binding.Name, serviceUri));
 }
        internal DiscoveryServerType(Type type, string uri) : base(typeof(DiscoveryServerProtocol))
        {
            this.schemaTable = new Hashtable();
            this.wsdlTable   = new Hashtable();
            uri             = new Uri(uri, true).GetLeftPart(UriPartial.Path);
            this.methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance));
            ServiceDescriptionReflector reflector = new ServiceDescriptionReflector();

            reflector.Reflect(type, uri);
            XmlSchemas schemas = reflector.Schemas;

            this.description = reflector.ServiceDescription;
            XmlSerializer serializer = ServiceDescription.Serializer;

            this.AddSchemaImports(schemas, uri, reflector.ServiceDescriptions);
            for (int i = 1; i < reflector.ServiceDescriptions.Count; i++)
            {
                ServiceDescription description = reflector.ServiceDescriptions[i];
                Import             import      = new Import {
                    Namespace = description.TargetNamespace
                };
                string key = "wsdl" + i.ToString(CultureInfo.InvariantCulture);
                import.Location = uri + "?wsdl=" + key;
                reflector.ServiceDescription.Imports.Add(import);
                this.wsdlTable.Add(key, description);
            }
            this.discoDoc = new DiscoveryDocument();
            this.discoDoc.References.Add(new ContractReference(uri + "?wsdl", uri));
            foreach (Service service in reflector.ServiceDescription.Services)
            {
                foreach (Port port in service.Ports)
                {
                    SoapAddressBinding binding = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
                    if (binding != null)
                    {
                        System.Web.Services.Discovery.SoapBinding binding2 = new System.Web.Services.Discovery.SoapBinding {
                            Binding = port.Binding,
                            Address = binding.Location
                        };
                        this.discoDoc.References.Add(binding2);
                    }
                }
            }
        }
        private static void ConstructServiceElement(InterfaceContract serviceInterfaceContract, bool isRoundTrip, System.Web.Services.Description.ServiceDescription desc, string serviceName, string portTypeName, List <ServiceEndpoint> endpoints)
        {
            // Generate <service> element optionally - sometimes necessary for interop reasons
            if (serviceInterfaceContract.NeedsServiceElement)
            {
                Service defaultService = null;
                if (isRoundTrip || desc.Services.Count == 0)
                {
                    // Create a new service element.
                    defaultService      = new Service();
                    defaultService.Name = serviceName;
                    foreach (ServiceEndpoint endpoint in endpoints)
                    {
                        if (endpoint.Binding.MessageVersion.Envelope == EnvelopeVersion.Soap11)
                        {
                            Port defaultPort = new Port();
                            defaultPort.Name    = serviceInterfaceContract.ServiceName + "Port";
                            defaultPort.Binding = new XmlQualifiedName(endpoint.Name.Replace(Constants.InternalContractName, portTypeName), desc.TargetNamespace);
                            SoapAddressBinding defaultSoapAddressBinding = new SoapAddressBinding();
                            defaultSoapAddressBinding.Location = GetDefaultEndpoint(endpoint.Binding, serviceInterfaceContract.ServiceName);
                            defaultPort.Extensions.Add(defaultSoapAddressBinding);
                            defaultService.Ports.Add(defaultPort);
                        }
                        else if (endpoint.Binding.MessageVersion.Envelope == EnvelopeVersion.Soap12)
                        {
                            Port soap12Port = new Port();
                            soap12Port.Name    = serviceInterfaceContract.ServiceName + "SOAP12Port";
                            soap12Port.Binding = new XmlQualifiedName(endpoint.Name.Replace(Constants.InternalContractName, portTypeName), desc.TargetNamespace);
                            Soap12AddressBinding soap12AddressBinding = new Soap12AddressBinding();
                            soap12AddressBinding.Location = GetDefaultEndpoint(endpoint.Binding, serviceInterfaceContract.ServiceName);
                            soap12Port.Extensions.Add(soap12AddressBinding);
                            defaultService.Ports.Add(soap12Port);
                        }
                    }

                    desc.Services.Add(defaultService);
                }
                else
                {
                    defaultService      = desc.Services[0];
                    defaultService.Name = serviceName;
                }
            }
        }
Esempio n. 19
0
    public override void ReflectDescription()
    {
        ServiceDescription description = ReflectionContext.ServiceDescription;

        foreach (Service service in description.Services)
        {
            foreach (Port port in service.Ports)
            {
                foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                {
                    SoapAddressBinding binding = extension as SoapAddressBinding;
                    if (null != binding)
                    {
                        binding.Location = binding.Location.Replace("http://", "https://");
                    }
                }
            }
        }
    }
Esempio n. 20
0
    public override void ReflectDescription()
    {
        ServiceDescription description = ReflectionContext.ServiceDescription;

        foreach (Service service in description.Services)
        {
            foreach (Port port in service.Ports)
            {
                foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                {
                    SoapAddressBinding binding = extension as SoapAddressBinding;
                    if (binding != null && !binding.Location.Contains("8092"))
                    {
                        binding.Location = binding.Location.Replace("92", "8092");
                    }
                }
            }
        }
    }
Esempio n. 21
0
        public override void ReflectDescription()
        {
            ServiceDescription description = ReflectionContext.ServiceDescription;

            foreach (Service service in description.Services)
            {
                foreach (Port port in service.Ports)
                {
                    foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                    {
                        SoapAddressBinding binding = extension as SoapAddressBinding;
                        if (null != binding)
                        {
                            string   loc_url   = binding.Location;
                            string[] tmprepstr = loc_url.Split('/');
                            binding.Location = binding.Location.Replace(tmprepstr[2], "huapi.paas.zj.chinamobile.com");//
                        }
                    }
                }
            }
        }
Esempio n. 22
0
        public override void ReflectDescription()
        {
            Console.WriteLine(ReflectionContext.ServiceDescription);
            ServiceDescription description = ReflectionContext.ServiceDescription;

            foreach (Service service in description.Services)
            {
                foreach (Port port in service.Ports)
                {
                    foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                    {
                        SoapAddressBinding binding = extension as SoapAddressBinding;
                        if (null != binding)
                        {
                            //binding.Location = binding.Location.Replace("http://mywebservice.comp.com", "https://uat.mywebservice.com");
                            binding.Location = "https://new.new";
                        }
                    }
                }
            }
        }
Esempio n. 23
0
        public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
        {
            foreach (object extension in context.WsdlPort.Extensions)
            {
                SoapAddressBinding addr = (extension as SoapAddressBinding);
                if (addr != null)
                {
                    addr.Location = this.location.ToString();
                }
            }

            EnumerateWsdlsAndSchemas(exporter.GeneratedWsdlDocuments, exporter.GeneratedXmlSchemas);

            foreach (ServiceDescription description in exporter.GeneratedWsdlDocuments)
            {
                FixImportAddresses(exporter.GeneratedWsdlDocuments, description, exporter.GeneratedXmlSchemas);
            }
            foreach (XmlSchema schema in exporter.GeneratedXmlSchemas.Schemas())
            {
                FixImportAddresses(exporter.GeneratedXmlSchemas, schema);
            }
        }
        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;
                }
            }
        }
 internal static EndpointAddress ImportAddress(Port wsdlPort)
 {
     if (wsdlPort != null)
     {
         XmlElement         xmlElement         = wsdlPort.Extensions.Find("EndpointReference", "http://www.w3.org/2005/08/addressing");
         XmlElement         xmlElement1        = wsdlPort.Extensions.Find("EndpointReference", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
         SoapAddressBinding soapAddressBinding = (SoapAddressBinding)wsdlPort.Extensions.Find(typeof(SoapAddressBinding));
         if (xmlElement != null)
         {
             return(EndpointAddress.ReadFrom(AddressingVersion.WSAddressing10, new XmlNodeReader(xmlElement)));
         }
         if (xmlElement1 != null)
         {
             return(EndpointAddress.ReadFrom(AddressingVersion.WSAddressingAugust2004, new XmlNodeReader(xmlElement1)));
         }
         if (soapAddressBinding != null)
         {
             return(new EndpointAddress(soapAddressBinding.Location));
         }
     }
     return(null);
 }
Esempio n. 26
0
        //HACK: FB instead of correctly showing the list of bindings we are simply picking the first this is incorrect howerver will do for the moment
        //I think we should be matching it to the binding
        public void Parse()
        {
            Name = _description.Name;

            foreach (Service service in _description.Services)
            {
                foreach (Port port in service.Ports)
                {
                    foreach (var extension in port.Extensions)
                    {
                        SoapAddressBinding soapBinding = extension as SoapAddressBinding;
                        if (soapBinding != null)
                        {
                            ServiceURI = soapBinding.Location;
                            goto finished;
                        }
                    }
                }

finished:
                break;
            }
        }
Esempio n. 27
0
        public override void ReflectDescription()
        {
            ServiceDescription description = ReflectionContext.ServiceDescription;

            foreach (Service service in description.Services)
            {
                foreach (Port port in service.Ports)
                {
                    foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                    {
                        SoapAddressBinding binding = extension as SoapAddressBinding;
                        if (null != binding)
                        {
                            Uri        locationWithPort = new Uri(binding.Location);
                            UriBuilder builder          = new UriBuilder(locationWithPort);
                            builder.Port = -1;
                            Uri locationWithoutPort = builder.Uri;
                            binding.Location = locationWithoutPort.AbsoluteUri;
                        }
                    }
                }
            }
        }
Esempio n. 28
0
    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");
    }
Esempio n. 29
0
    public static void Main()
    {
// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
// <Snippet5>
        // Read a ServiceDescription from existing WSDL.
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("Input_CS.wsdl");

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

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

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

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

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

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

        mySoapPort.Name = "MathServiceSoap";

        mySoapPort.Binding = myXmlQualifiedName;

        SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();

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

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

        Port myHttpGetPort = new Port();

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

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

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

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

        // Write to a new WSDL file.
        myServiceDescription.Write("output.wsdl");
// </Snippet1>
    }
Esempio n. 30
0
        // See comment on the ServerProtocol.IsCacheUnderPressure method for explanation of the excludeSchemeHostPortFromCachingKey logic.
        internal DiscoveryServerType(Type type, string uri, bool excludeSchemeHostPortFromCachingKey)
            : base(typeof(DiscoveryServerProtocol))
        {
            if (excludeSchemeHostPortFromCachingKey)
            {
                this.UriFixups = new List <Action <Uri> >();
            }
            //
            // parse the uri from a string into a Uri object
            //
            Uri uriObject = new Uri(uri, true);

            //
            // and get rid of the query string if there's one
            //
            uri        = uriObject.GetLeftPart(UriPartial.Path);
            methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
            ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(this.UriFixups);

            reflector.Reflect(type, uri);

            XmlSchemas schemas = reflector.Schemas;

            this.description = reflector.ServiceDescription;

            // We need to force initialization of ServiceDescription's XmlSerializer since we
            // won't necessarily have the permissions to do it when we actually need it
            XmlSerializer serializer = ServiceDescription.Serializer;

            // add imports to the external schemas
            AddSchemaImports(schemas, uri, reflector.ServiceDescriptions);

            // add imports to the other service descriptions
            for (int i = 1; i < reflector.ServiceDescriptions.Count; i++)
            {
                ServiceDescription description = reflector.ServiceDescriptions[i];
                Import             import      = new Import();
                import.Namespace = description.TargetNamespace;

                //


                string id = "wsdl" + i.ToString(CultureInfo.InvariantCulture);

                import.Location = uri + "?wsdl=" + id;
                this.AddUriFixup(delegate(Uri current)
                {
                    import.Location = CombineUris(current, import.Location);
                });
                reflector.ServiceDescription.Imports.Add(import);
                wsdlTable.Add(id, description);
            }

            discoDoc = new DiscoveryDocument();
            ContractReference contractReference = new ContractReference(uri + "?wsdl", uri);

            this.AddUriFixup(delegate(Uri current)
            {
                contractReference.Ref    = CombineUris(current, contractReference.Ref);
                contractReference.DocRef = CombineUris(current, contractReference.DocRef);
            });
            discoDoc.References.Add(contractReference);

            foreach (Service service in reflector.ServiceDescription.Services)
            {
                foreach (Port port in service.Ports)
                {
                    SoapAddressBinding soapAddress = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
                    if (soapAddress != null)
                    {
                        System.Web.Services.Discovery.SoapBinding binding = new System.Web.Services.Discovery.SoapBinding();
                        binding.Binding = port.Binding;
                        binding.Address = soapAddress.Location;
                        this.AddUriFixup(delegate(Uri current)
                        {
                            binding.Address = CombineUris(current, binding.Address);
                        });
                        discoDoc.References.Add(binding);
                    }
                }
            }
        }