2

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))。バインディングがメッセージと同じバージョンで構成されていることを確認してください。

誰かが私が間違っていることを知っていますか?

前もって感謝します。

4

1 に答える 1

1
Message.CreateMessage(MessageVersion.Soap12,  

MessageVersion 列挙値の代わりに、バインディングに一致Soap12するように指定する必要がありますSoap12Addressing10

于 2012-09-28T09:28:17.777 に答える