我自己写了个程序test,不过没成功,返回null.
Console application 用来一运行,就host 一个service 在 http://127.0.0.1/hellousing 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 = "[email protected]";                //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>

解决方案 »

  1.   

    既然是service,只运行在一台机器上也就可以啊。
    你打开谷歌浏览器或者firefox+firebug,看看network那里请求返回的是什么。
      

  2.   

    怎么host的没有什么关系,你指定好address。
    另外通过url调用需要使用webhttp的binding。
    不指定这个binding是不可以的。你试试看。
      

  3.   


    如果把127.0.0.1/hello address 加到 service reference, web.config中会有binding 配置,可是jquery如何用呢?
      

  4.   


    如果把127.0.0.1/hello address 加到 service reference, web.config中会有binding 配置,可是jquery如何用呢?http://www.cnblogs.com/artech/archive/2012/02/15/wcf-rest.html 
    WCF很多经典系列
      

  5.   

    研究出来了,外部网站调用机器上的可执行程序,理论上不可能的,因为这是一种黑客行为。如果有这个需求,比如,通过web打开word,首先要把word这个程序在注册表注册,然后建立一个互信协议,外部网站通过这个协议调用word.exe文件,就可以了。