WCF web服务没有正确执行序列化

本文关键字:执行 序列化 web 服务 WCF | 更新日期: 2023-09-27 18:10:02

我的解决方案中有WCF web服务。服务具有在服务类中实现的接口。我在接口中添加了一些新方法,并在服务类中实现。我可以访问,如果我使用服务DLL引用到我的asp.net MVC 3应用程序。但是在部署和添加服务的服务引用后,我无法获得新添加的方法。通过创建客户端对象。为什么会发生这种情况?我在远程服务器上部署了服务。

我也检查了wsdl,但没有找到关于新添加方法的元数据。

编辑:好吧好吧……我不知道发生了什么,不知怎么的,我得到了我所期望的序列化对象。但是当我对这些对象执行任何操作时,我遇到了无法连接到服务的问题。

    "An error occurred while receiving the HTTP response to http://MyServer/MyAdminService.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."
Inner Exception: 
"The underlying connection was closed: An unexpected error occurred on a receive"

为什么要这样?web的必要属性是什么?配置需要在客户端和服务器对象之间建立连接吗?

解决:http://lalitcdhake.blogspot.com/2011/10/serialization -与-实体框架- 4. - html

欢呼

WCF web服务没有正确执行序列化

http://lalitcdhake.blogspot.com/2011/10/serialization-with-entity-framework-4.html

您是否用OperationContract属性标记了新方法?来自msdn:

的示例<>之前[ServiceContract(名称空间="Microsoft.WCF.Documentation")]ISampleService{//明确保护级别要求。(OperationContract)字符串SampleMethod(字符串msg);}类SampleService{#region ISampleService Members公共字符串SampleMethod(字符串msg){控制台。WriteLine("被调用:{0}",msg);返回"The service greeting you: " + msg;}# endregion}

我想你有一个部署问题。有些事情值得尝试。

  1. 确认您的方法在您的本地wsdl中可用。如果方法在本地可用,则问题与序列化无关。
  2. 确认您部署到的远程服务器实际上就是您在检查远程wsdl时要查看的服务器。有很多方法可以做到这一点,但一个简单的方法是在web配置中引入一个错误并确认应用程序关闭(如果这是一个开发服务器并且关闭应用程序是无害的)。