Skip to content

Instantly share code, notes, and snippets.

@euhmeuh
Created June 15, 2017 08:56
Show Gist options
  • Save euhmeuh/ec8e3cc17d9171abd30562386779bf48 to your computer and use it in GitHub Desktop.
Save euhmeuh/ec8e3cc17d9171abd30562386779bf48 to your computer and use it in GitHub Desktop.
Initialize a WCF web server with SOAP support
import zeep
class Program:
def __init__(self):
self.client = zeep.Client("http://localhost:8080/wsdl")
def run(self):
response = self.client.service.CreateCorporateCat("Skippy")
print(response)
if __name__ == '__main__':
program = Program()
program.run()
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.Threading;
namespace SoapServer
{
public class Program
{
private static readonly ManualResetEvent Exit = new ManualResetEvent(false);
private static readonly string Url = "http://localhost:8080";
public static void Main(string[] args)
{
var host = new ServiceHost(typeof(CorporateService), new Uri(Url));
var soapEndpoint = host.AddServiceEndpoint(typeof(ICorporateService), new BasicHttpBinding(), "soap");
var webEndpoint = host.AddServiceEndpoint(typeof(ICorporateService), new WebHttpBinding(), "web");
webEndpoint.Behaviors.Add(new WebHttpBehavior());
var smb = new ServiceMetadataBehavior
{
HttpGetEnabled = true,
HttpGetUrl = new Uri(Url + "/wsdl")
};
host.Description.Behaviors.Add(smb);
Console.CancelKeyPress += (sender, e) => { e.Cancel = true; Exit.Set(); };
host.Open();
Exit.WaitOne();
host.Close();
}
}
public class CorporateService : ICorporateService
{
public string CreateCorporateCat(string name)
{
return $"A new office cat named {name} is born!";
}
}
[ServiceContract]
public interface ICorporateService
{
[OperationContract]
[WebGet]
string CreateCorporateCat(string name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment