Created
June 15, 2017 08:56
-
-
Save euhmeuh/ec8e3cc17d9171abd30562386779bf48 to your computer and use it in GitHub Desktop.
Initialize a WCF web server with SOAP support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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