我创建了 ASP.NET 应用程序并向其添加了简单的 WCF 服务。ASP.NET 应用程序是 WCF 服务的宿主。服务正在运行。
该服务如下所示:
[ServiceContract]
public interface IService1
{
    [OperationContract]
    string DoWork(string text);
}
public class Service1 : IService1
{
    public string DoWork(string text)
    {
        return text.ToUpper();
    }
}
在客户端是应动态调用 WCF 服务的控制台应用程序。我使用以下代码:
WSHttpBinding binding = new WSHttpBinding(SecurityMode.None);
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(
   new BindingParameterCollection());
factory.Open();
EndpointAddress address = new EndpointAddress("http://localhost:3929/Service1.svc");
IRequestChannel irc = factory.CreateChannel(address);
using (irc as IDisposable)
{
    irc.Open();
    XmlReader reader = XmlReader.Create(new StringReader(
        @"<DoWork xmlns='http://tempuri.org/'>
        <composite xmlns:a='http://www.w3.org/2005/08/addressing' 
        xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
        <a:StringValue>aaaa</a:StringValue>
        </composite>
        </DoWork>"));
    Message m = Message.CreateMessage(MessageVersion.Soap12,  
                "http://tempuri.org/IService1/DoWork", reader);
    Message ret = irc.Request(m);
    reader.Close();
    Console.WriteLine(ret);
}
//close the factory
factory.Close();
但是,它在这一行崩溃:
Message ret = irc.Request(m);
出现以下错误:
传出消息的消息版本 (Soap12 ( http://www.w3.org/2003/05/soap-envelope ) AddressingNone ( http://schemas.microsoft.com/ws/2005/05/addressing/none ) ) 与编码器 (Soap12 ( http://www.w3.org/2003/05/soap-envelope ) Addressing10 ( http://www.w3.org/2005/08/addressing ))不匹配。确保绑定配置为与消息相同的版本。
有人知道我做错了什么吗?
先感谢您。