我已經創建了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
這沒有任何意義。您確定在進行更改後重新編譯了嗎? –