我已经创建了ASP.NET应用程序并向其添加了简单的WCF服务。 ASP.NET应用程序是WCF服务的主机。该服务正在运行。动态调用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);
与以下错误:
The message version of the outgoing message (Soap12 (http://www.w3.org/2003/05/soap-envelope) AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none)) does not match that of the encoder (Soap12 (http://www.w3.org/2003/05/soap-envelope) Addressing10 (http://www.w3.org/2005/08/addressing)). Make sure the binding is configured with the same version as the message.
有谁知道我做错了吗?
预先感谢您。
我有同样的错误。 – tesicg
这没有任何意义。您确定在进行更改后重新编译了吗? –