c# - 与 WCF 服务通信产生未实现异常

标签 c# wcf

我有一个应用程序正在对我在本地 IIS 服务器上托管的一些 WCF 服务进行调用。 IIS 服务器运行 ASP.NET 4.0 classic,服务是使用 .NET 4.0 开发的。客户端正在运行 Windows Compact Framework 3.5,并使用 NetCFSvcUtil 实用程序自动生成服务客户端。

当我尝试在应用程序中调用客户端可用的方法之一时,我收到以下异常:

ProtoccolException:远程服务器返回意外响应:(501) 未实现。

任何人都可以指出我为什么收到此错误吗?我调用的所有方法都提供了实现。

堆栈跟踪:

System.ServiceModel.ProtocolException was unhandled
  Message="The remote server returned an unexpected response: (501) Not Implemented."
  StackTrace:
       at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message)
       at ClientProject.Microsoft.Tools.ServiceModel.CFClientBase`1.getReply(Message msg)
       at ClientProject.Microsoft.Tools.ServiceModel.CFClientBase`1.Invoke[TREQUEST,TRESPONSE](CFInvokeInfo info, TestMethodRequest request)
       at ClientProject.TestService.MQClient.TestMethod(TestMethodRequest request)
       at ClientProject.TestService.MQClient.TestMethod(TestInfo testInfo)
       at ClientProject.Form.Button1_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at ClientProject.Form.Main()
  InnerException: System.Net.WebException
       Message="The remote server returned an error: (501) Not Implemented."
       StackTrace:
            at System.Net.HttpWebRequest.finishGetResponse()
            at System.Net.HttpWebRequest.GetResponse()
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
            at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
            at System.ServiceModel.Channels.RequestChannel.Request(Message message)
            at ClientProject.Microsoft.Tools.ServiceModel.CFClientBase`1.getReply(Message msg)
            at ClientProject.Microsoft.Tools.ServiceModel.CFClientBase`1.Invoke[TREQUEST,TRESPONSE](CFInvokeInfo info, TestMethodRequest request)
            at ClientProject.TestService.MQClient.TestMethod(TestMethodRequest request)
            at ClientProject.TestService.MQClient.TestMethod(TestInfo testInfo)
            at ClientProject.Form.Button1_Click(Object sender, EventArgs e)
            at System.Windows.Forms.Control.OnClick(EventArgs e)
            at System.Windows.Forms.Button.OnClick(EventArgs e)
            at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
            at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
            at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
            at System.Windows.Forms.Application.Run(Form fm)
            at ClientProject.Form.Main()
       InnerException: 

在我的服务上运行 WCF 测试客户端 会产生以下最内部的异常:

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.


An error occurred while receiving the HTTP response to http://wv113.domain.local/Development/TestService.svc. 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.

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.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 IMQClient.TestMethod(TestInfo testInfo)
   at MQClient.TestMethod(TestInfo testInfo)

Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
   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)

Inner Exception:
An existing connection was forcibly closed by the remote host
   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)

更新:我的服务器上的所有内容都已正确配置。这些问题实际上是由于我的本地开发计算机缺少其中一项服务的消息队列组件造成的。另一个服务抛出异常,因为给我的一个配置文件中有错误的设置。学过的知识?检查日志文件!

最佳答案

这意味着您尝试执行的方法未在 WCF 服务器端实现。这是你写的吗?

抛出此异常的方法示例:

public void UnimplementedMethod()
{
    throw new NotImplementedException();
}

这通常是通过实现类继承的接口(interface)自动生成的方法的默认标记。

编辑:

要确保该方法在 Web 服务端实现,请转到 Visual Studio 命令提示符并键入 wcftestclient。应用程序启动后,将服务引用添加到要测试的 wcf 并从那里执行方法,以确保其按预期运行。

关于c# - 与 WCF 服务通信产生未实现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11107956/

相关文章:

c# - 查找 ASP.Net 超时原因(在长时间操作期间)

c# - 在 Visual Studio 中的 WPF 项目上找不到本地数据库

c# - 日志级别是否有接近共识的指南?

c# - 使用枚举表示C#中的ID

.net - "Leaking"线程句柄

.net - 使用 ContractNamespace 属性设置 WCF DataContract 命名空间

c# - 如何从 .NET Core 上的 WCF SOAP 客户端记录 http 级流?

c# - 需要帮助使用 .Net 技术制作试用版产品

c# - AutoMapper:Int 到 String 并返回

c# - 从 C# 调用 WCF 时如何增加 MaxReceivedMessageSize