- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在用 Visual Basic .NET 编写一个程序来在我本地网络上的 PC 上执行操作。
我基本上是在寻找某种极其简单的解决方案,以允许我:
示例:输入 http://192.168.1.72/function/argument1/argument2
将在该(本地联网)机器上的我的 winforms 应用程序中运行“函数”子/函数,并通过 argument1 和 argument2(如果包含它们),则将响应页面/字符串作为反馈返回给请求浏览器
谁能指出我的方法来做到这一点?我正在寻找相当简单但可靠的东西,因为它最终可能会全天候运行
最佳答案
I'm looking for something fairly simple, but reliable because it may end up running around the clock
我认为最简单的方法是使用 WebServiceHost WCF 类:
[ServiceContract]
public class MyService
{
[OperationContract, WebGet(UriTemplate = "/function/{argument1}/{argument2}")]
public string AMethod(string argument1, string argument2)
{
return argument1 + " " + argument2;
}
}
将此行放入您的应用程序的表单加载(或任何其他入口点),
var wsh = new WebServiceHost(typeof(MyService), new Uri("http://0.0.0.0/MyService"));
wsh.Open();
并从您的浏览器调用 http://192.168.1.72/Myservice/function/a/b
。就是这样。
----完整的工作代码----
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
var wsh = new WebServiceHost(typeof(MyService), new Uri("http://0.0.0.0/MyService"));
wsh.Open();
}
}
[ServiceContract]
public class MyService
{
[OperationContract, WebGet(UriTemplate = "/function/{argument1}/{argument2}")]
public string AMethod(string argument1, string argument2)
{
return argument1 + " " + argument2;
}
///******** EDIT ********
///
[OperationContract, WebGet(UriTemplate = "/function2/{argument1}/{argument2}")]
public Stream F2(string argument1, string argument2)
{
return ToHtml("<html><h1>" + argument1 + " " + argument2 + "</h1></HtmlDocument>");
}
static Stream ToHtml(string result)
{
var data = Encoding.UTF8.GetBytes(result);
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html; charset=utf-8";
WebOperationContext.Current.OutgoingResponse.ContentLength = data.Length;
return new MemoryStream(data);
}
///END OF EDIT
}
}
is it possible to determine the IP address the request is coming from?
var m = OperationContext.Current
.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
var address = m.Address;
any way to make the {arguments} optional?
只需从 WebGet
属性中删除 UriTemplate
参数。那么你的网址将是
http://1192.168.1.72/MyService/AMethod?argument1=aaaa&argument2=bbb
如果你想让 argument2 对于 ex 是可选的,调用 as
http://1192.168.1.72/MyService/AMethod?argument1=aaaa
argument2 将在您的方法中获取默认值。
关于.net - 通过本地网络的 URL 调用子程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15852859/
我有一个包含很多工作表和几个宏的工作簿。当我进入 VBA 并尝试将新的 Sub 写入 ThisWorkbook 模块时,我看到: "This will reset your project, proc
1、函数定义 子程序即一段分离的代码,它可以使减少重复代码且程序易读.perl中,子程序可以出现在程序的任何地方.但一般放在程序的开始或结尾. 复制代码 代码如下:
1、定义 子程序即执行一个特殊任务的一段分离的代码,它可以使减少重复代码且使程序易读。PERL中,子程序可以出现在程序的任何地方。定义方法为: &n
如何将 deck(52) 数组从 Newgame 函数传递到 deckshuffle 函数 FUNCTION newgame 'New game RANDOMIZE TIMER CA
有没有办法在后台运行 perl 子程序?我环顾四周,看到了一些关于线程的提及,但看到一个例子会有所帮助,或者为我指明正确的方向。谢谢。 想跑run_sleep在后台。 #!/usr/bin/perl
情况 我正在创建一个简单的模板文件,该文件将有助于创建 future 的脚本,以便在 *nix 系统上通过命令行执行各种任务。作为其中的一部分,我可能会要求用户输入需要根据源代码中提供的正则表达式进行
我想将以下变量传递给子程序 mySubroutine,$name, $age然后是这个多维数组: $name = "jennifer"; $age = 100; $list[0][0] = "TEST
据我所知,VB6不支持继承,但它支持接口(interface)。我正在尝试创建一个重载子例程,将其信息传递给基类的同名子例程。 Sub Main() Dim Student1 as New S
这个问题已经有答案了: Dynamic Function Calls in Excel VBA (1 个回答) 已关闭 8 年前。 这是我的测试代码 Sub dotask() Dim qusu
我正在编写一个本质上是静态的函数。我想将它插入到模板工具包中,它会传递类名。本质上,它正在做 ClassName->function( $args.. ) 但我希望它做类似的事情 ClassName:
我创建了一个小示例程序来检查子例程系统调用。 package main func print() { } func main() { go print() } go 子程序的 straces
我是该网站的新手,这看起来可能是获得一些提示和帮助(如果有的话)的地方。 我正在学习“C 调用 Fortran 子程序”,我对 C 有一定的了解,但对 Fortran 了解不多。 优点:我看过一些例子
是否有一种方法/功能可以为所有可用的 Mojolicious 路由编写自动启动子程序/方法? 也许是一个自动助手,但我还不知道如何去做。 我认为这对于为几乎所有可用路由初始化数据库连接 $self->
我试图在不实例化对象的情况下从类中调用原型(prototype)函数。我的类(class) MyClass 的一个例子: package MyClass; use strict; use warnin
我正在尝试从 C 调用 FORTRAN 函数 我的问题是: 如果 fortRoutine 是我的 fortran 子例程的名称,那么我从 C 调用它作为 fortRoutine_。如果 fortRou
我可以调用编译这个 fortran 代码 'test.f90' subroutine test(g,o) double precision, intent(in):: g double precisi
我制作了一个 Perl 模块 MyModule.pm 它有一些我想在 shell 脚本中调用的子例程 getText。我尝试了以下方式,但它给出了错误; SEC_DIR=`perl -MMyModul
我用 CommaIde 打开了这个简单的脚本: #!/usr/bin/env perl6 my $str = 'foobar'; say $str; IDE 突出显示了带有错误的“说”一词: Subr
我基本上有一个存储有数字 1-6(例如垄断)的立方体 vector > cube; 看起来像这样: 0300 5126 0400 我有将它倒转的代码: short tmp=cube[0][1]; cu
我必须在两个文件中创建一个 surbroutine,我在构建项目时遇到问题,出现错误: undefined reference to c 我不知道发生了什么,我正在尝试发送 C[0] 内存方向,这就是
我是一名优秀的程序员,十分优秀!