asp.net 如何调用self host的 wcf service

guotong360 2013-06-14 03:31:40
有一个windows 程序 A,是图片处理的,运行以后会在127.0.0.1 创建一个wcf service,其他程序可以通过访问这个service来控制 A,比如给图片加个文字层这类的。其它程序如果是windows,当然没有问题。

现在问题来了,新需求是通过asp.net application B 来调用这个service,asp.net application 不在同一个机器,也不再同一个domain。我大致知道应该用script 来完成,不过不知道怎样写code.对了,首先是,这样的要求可以实现吗?我知道这样设计不是很好,不过那个图片处理程序比较复杂,把它转换成web版本太麻烦了,而且在asp.net page上加工图片效率也不高。所以寻找这样的方案。

这是一个公司内部用的,所以我能保证每一个访问 B(asp.net app)的机器上都已将安装了A。

谢谢
...全文
133 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
guotong360 2014-01-10
  • 打赏
  • 举报
回复
研究出来了,外部网站调用机器上的可执行程序,理论上不可能的,因为这是一种黑客行为。如果有这个需求,比如,通过web打开word,首先要把word这个程序在注册表注册,然后建立一个互信协议,外部网站通过这个协议调用word.exe文件,就可以了。
UEAnswer 2013-06-17
  • 打赏
  • 举报
回复
引用 4 楼 u010595796 的回复:
[quote=引用 3 楼 waiting593 的回复:] 怎么host的没有什么关系,你指定好address。 另外通过url调用需要使用webhttp的binding。 不指定这个binding是不可以的。你试试看。
如果把127.0.0.1/hello address 加到 service reference, web.config中会有binding 配置,可是jquery如何用呢?[/quote] http://www.cnblogs.com/artech/archive/2012/02/15/wcf-rest.html WCF很多经典系列
guotong360 2013-06-15
  • 打赏
  • 举报
回复
引用 3 楼 waiting593 的回复:
怎么host的没有什么关系,你指定好address。 另外通过url调用需要使用webhttp的binding。 不指定这个binding是不可以的。你试试看。
如果把127.0.0.1/hello address 加到 service reference, web.config中会有binding 配置,可是jquery如何用呢?
UEAnswer 2013-06-14
  • 打赏
  • 举报
回复
怎么host的没有什么关系,你指定好address。 另外通过url调用需要使用webhttp的binding。 不指定这个binding是不可以的。你试试看。
潮起潮落 2013-06-14
  • 打赏
  • 举报
回复
既然是service,只运行在一台机器上也就可以啊。 你打开谷歌浏览器或者firefox+firebug,看看network那里请求返回的是什么。
guotong360 2013-06-14
  • 打赏
  • 举报
回复
我自己写了个程序test,不过没成功,返回null. Console application 用来一运行,就host 一个service 在 http://127.0.0.1/hello using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Activation; namespace SelfHost { [ServiceContract] public interface IHelloWorldService { [OperationContract] string SayHello(string name); } [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class HelloWorldService : IHelloWorldService { public string SayHello(string name) { return string.Format("Hello, {0}", name); } } class Program { static void Main(string[] args) { Uri baseAddress = new Uri("http://127.0.0.1/hello"); // Create the ServiceHost. using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), 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(); } } } } Jquery 调用self hosted service. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebAutomation.aspx.cs" Inherits="WebApplication2.WebAutomation" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> function invokeService() { $(document).ready(function () { var user = "user@mail.com"; //Calling WCF Service using jQuery ajax method $.ajax({ type: "GET", async: "false", url: "http://127.0.0.1/hello", data: user, contentType: "application/json", dataType: "jsonp", processData: true, method: "SayHello", success: function (result) { AjaxSucceeded(result); }, error: AjaxFailed }); //Additional way of calling WCF service using getJSON() JQuery method $.getJSON("http://127.0.0.1/hello/SayHello?name=user", {}, function (data) { alert(data); }); }); } function AjaxSucceeded(result) { alert(result); } function AjaxFailed(result) { alert(result.status + ' ' + result.statusText); } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" onclick="javascript: invokeService();" value="Call WCF Service" /> </div> </form> </body> </html>

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧