0

簡単なWCFデモを作成しました:サーバー側:

namespace ServerSide
{
    class Program
    {
        static void Main(string[] 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();
        }
    }
}

クライアント側:

    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();
            }
        }
     }

次に、ServerSideを実行します。CLientSideを実行しようとすると、次のエラーメッセージが表示されます。http:// locahost:8000 / HelloIndigo/HelloIndigoService へのHTTP応答の受信中にエラーが発生しました。これは、HTTPプロトコルを使用していないサービスエンドポイントバインディングが原因である可能性があります。これは、サーバーによってHTTP要求コンテキストが中止されたことが原因である可能性もあります(おそらくサービスのシャットダウンが原因です)。詳細については、サーバーログを参照してください。

そしてエラーの詳細:

    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: 
4

1 に答える 1

2

あなたのマシンは呼ばれていますlocahostか?? 通常、これらのマシンはローカル ホストと呼ばます。そのため、サービス用に次の URL を試してください (サーバー側とクライアント側の両方で):

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

この変更により、問題なくサンプルを再作成することができました。

于 2010-08-21T08:57:52.900 に答える