开发者

weird error about WCF -- System.ServiceModel.CommunicationException was unhandled

I created a simple WCF demo: Server Side:

namespace ServerSide
{
    class Program
    {
        static void Main(st开发者_开发问答ring[] args)
        {
            System.ServiceModel.ServiceHost host = 
                new System.ServiceModel.ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri("http://locahost:8000/HelloIndigo"));
            host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new System.ServiceModel.BasicHttpBinding(), "HelloIndigoService");
            host.Open();

            Console.Write("Terminate Server");
            Console.ReadLine();
        }
    }
}

Client Side:

    namespace ClientSide
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.ServiceModel.EndpointAddress ep =
                    new System.ServiceModel.EndpointAddress("http://locahost:8000/HelloIndigo/HelloIndigoService");
                IHelloIndigoService proxy = 
                    System.ServiceModel.ChannelFactory<IHelloIndigoService>.CreateChannel(new System.ServiceModel.BasicHttpBinding(), ep);
                string s = proxy.HelloIndigo();
                Console.WriteLine(s);
                Console.ReadLine();
            }
        }
     }

Then, run ServerSide, when I tried to run the CLientSide, I got following error msg: An error occurred while receiving the HTTP response to http://locahost:8000/HelloIndigo/HelloIndigoService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

And the error details:

    System.ServiceModel.CommunicationException was unhandled
      Message="An error occurred while receiving the HTTP response to http://locahost:8000/HelloIndigo/HelloIndigoService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."
      Source="mscorlib"
      StackTrace:
        Server stack trace: 
           at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
           at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
        Exception rethrown at [0]: 
           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
           at ClientSide.IHelloIndigoService.HelloIndigo()
           at ClientSide.Program.Main(String[] args) in E:\My_Test\Test_for_VS2008\WCF_TestLessonOne_Client\ClientSide\Program.cs:line 16
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.Net.WebException
           Message="The underlying connection was closed: An unexpected error occurred on a receive."
           Source="System"
           StackTrace:
                at System.Net.HttpWebRequest.GetResponse()
                at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           InnerException: System.IO.IOException
                Message="Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
                Source="System"
                StackTrace:
                     at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                     at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                     at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
                InnerException: System.Net.Sockets.SocketException
                     Message="An existing connection was forcibly closed by the remote host"
                     Source="System"
                     ErrorCode=10054
                     NativeErrorCode=10054
                     StackTrace:
                          at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                      at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                 InnerException: 


Is your machine called locahost ?? Typically, those machines are called localhost - so try this Url for your service (both on server and client side):

new Uri("http://localhost:8000/HelloIndigo")

With this change, I was able to re-create your sample without any issues whatsoever.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜