应该用哪个binding?         
 binding="basicHttpBinding"
 binding="wsHttpBinding"我用这两个都不行,是否一定要宿主在iis上?

解决方案 »

  1.   

    不是啊,你用console host的话host程序运行了吗
      

  2.   

    控制台能运行,能ie打开报错:- <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    - <s:Body>
    - <s:Fault>
      <faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode> 
      <faultstring xml:lang="zh-CN">由于 ContractFilter 在 EndpointDispatcher 不匹配,因此 Action 为“”的消息无法在接收方处理。这可能是由于协定不匹配(发送方和接收方 Action 不匹配)或发送方和接收方绑定/安全不匹配。请检查发送方和接收方是否具有相同的协定和绑定(包括安全要求,如 Message、Transport、None)。</faultstring> 
      </s:Fault>
      </s:Body>
      </s:Envelope>
      

  3.   

    我简单测试了一下,完全没问题.
    Host:using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    namespace MyConsoleHost
    {
        class Program
        {
            static void Main(string[] args)
            { 
                using (ServiceHost host = new ServiceHost(typeof(HelloIndigoService),
    new Uri("http://157.60.113.68:7999/HelloIndigo")))
                {
                    host.AddServiceEndpoint(typeof(IHelloIndigoService),
                new BasicHttpBinding(), "HelloIndigoService");
                    ServiceMetadataBehavior mexBehavior =
    host.Description.Behaviors.Find<ServiceMetadataBehavior>();                if (mexBehavior == null)
                    {
                        mexBehavior = new ServiceMetadataBehavior();
                        mexBehavior.HttpGetEnabled = true;
                        host.Description.Behaviors.Add(mexBehavior);
                    }                host.Open();                Console.WriteLine("Press <ENTER> to terminate the service host");
                    Console.ReadLine();
                }        }
        }
    }Contract和实现,我放一起看起来方便:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    namespace MyConsoleHost
    {
        [ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")]
            public interface IHelloIndigoService
            {
                [OperationContract(Action="http://tempuri.org/HelloWorld")]            string HelloIndigo();
            }    public class HelloIndigoService : IHelloIndigoService
        {
            public string HelloIndigo()
            {
                return "Hello Indigo";
            }
        }}consume:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    namespace MyClient
    {
        class Program
        {
            [ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")]
            public interface IHelloIndigoService
            {
                [OperationContract]
                string HelloIndigo();
            }        static void Main(string[] args)
            {
                EndpointAddress ep = new
    EndpointAddress("http://157.60.113.68:7999/HelloIndigo/HelloIndigoService");            IHelloIndigoService proxy = ChannelFactory<IHelloIndigoService>.
              CreateChannel(new BasicHttpBinding(), ep);
                string s = proxy.HelloIndigo();
                Console.WriteLine(s);            Console.WriteLine("Press <ENTER> to terminate Client.");
                Console.ReadLine();        }
        }
    }没有写config文件.如果这个可以应该是config文件的问题.
      

  4.   

    另外看看你请求的地址是否正确.我的例子应该用
    http://157.60.113.68:7999/HelloIndigo?wsdl
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    namespace MyClient
    {
        class Program
        {
            static void Main(string[] args)
            {
                ServiceReference1.HelloIndigoServiceClient c = new MyClient.ServiceReference1.HelloIndigoServiceClient();
                Console.Write(c.HelloIndigo());
                Console.WriteLine("Press <ENTER> to terminate Client.");
                Console.ReadLine();        }
        }
    }
    也试过,一样没问题.
      

  6.   

    我之所以让它生成webservice就是客户端不是framework 3.0或3.5的版本,可能是framework 1.1,这样行吗?