我简单测试了一下,完全没问题. 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文件的问题.
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(); } } } 也试过,一样没问题.
- <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>
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文件的问题.
http://157.60.113.68:7999/HelloIndigo?wsdl
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(); }
}
}
也试过,一样没问题.