WCF REST Client Exception
I have the following WCF client code:
string add = String.Format("http://localhost:{0}/ServiceRequestRest",accessPort);
var cf = new ChannelFactory<IServiceRequestRest>(new WebHttpBinding(), add);
cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
busService = cf.CreateChannel();
busService.DoMyStuff("hello",null);
When I have "first chance exception break" activated, that last line of code throws a series of exceptions. The first exception is this:
System.InvalidOperationException occurred Message="Envelope Version 'EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)' does not support adding Message Headers." Source="System.ServiceModel" StackTrace: at System.ServiceModel.Channels.MessageHeaders.ValidateHeaderKind(HeaderKind headerKind)
I am not aware that I am trying to "add Message Headers", but I choose to continue execution and immediately get the next exception:
System.Net.WebException occurred Message="The underlying connection was closed: The connection was closed unexpectedly." Source="System" StackTrace: at System.Net.HttpWebRequest.GetResponse()
With all that said, I'm having difficulty understanding what the problem is. Any clues?
Update: The return type of my REST call could not be serialized, as I learned from another site. That alone could cause this problem, but after I fixed it I still had the same problem. When I use a regular 开发者_开发技巧catch block for the exception, all I get is "the connection was closed unexpectedly." What else could I be missing?
Update2: I think I found the final problem. I was getting interference from Skype. The code is working now. :)
The main problem that I see is that you are trying to use a WCF Channel to communicate using WebHttpBinding.
IMHO the entire purpose of WebHttpBinding was so that the client did not have to use the WCF stack to communicate with it. You simply use any HTTP stack to make the requests.
精彩评论