Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.

When using "ChannelFactory" to try to consume WCF Restful Service, e.g.:

Service

[ServiceContract]
    public interface ISocialStatus
    {
        [OperationContract]
        [WebGet(UriTemplate =
        "/statuses/update/{text}")]
        void UpdateStatus(string text);
    }


Client:

 using (ChannelFactory factory = new ChannelFactory("SocialClient"))
            {
                ISocialStatus socialChannel = factory.CreateChannel();
                socialChannel.UpdateStatus("aaa");
            }

Solution:

Way 1: Add WebHttpBehavior

using (ChannelFactory factory = new ChannelFactory("SocialClient"))
            {
                factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
                ISocialStatus socialChannel = factory.CreateChannel();
                socialChannel.UpdateStatus("aaa");
            }

Way 2: Use WebChannelFactory

 using (System.ServiceModel.Web.WebChannelFactory factory = new WebChannelFactory("SocialClient"))
            {
                ISocialStatus socialChannel = factory.CreateChannel();
                socialChannel.UpdateStatus("aaa");
            }


你可能感兴趣的:(WCF,service,interface,wcf,string)