Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1528
  • Last Modified:

Webservice : Unable to serialize the interface

Hi Experts,

I have a project with contains my interface ( ITest ).

public interface ITest
{
void myfunction(string data);            
}

In my webservices project (second one), I build the service1.asmx like this:

[WebMethod]
public string HelloWorld(ITest test)
{
      return "Hello World";
}

When I add a webreference to my last project to test my webservice service1.asmx, Visual Studio throw me the exception:
Unable to serialize the interface.

Thanks in advance for helping me to solve my problem.
0
noulouk
Asked:
noulouk
  • 2
2 Solutions
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
Interfaces cannot be passed as webmethod parameters, nor can they be returned.

You'll need to write a real object and pass that instead. This has to do with the fact that although all methods of an interface are known, it cannot be properly deserialized back into an object as there is no explicit knowledge of the underlying type.
0
 
jonvaughanCommented:
In addition to this you have to make sure that the object you do choose is serializable too .
0
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
ofcourse ;)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now