I’m trying to use WCF for the first time however I hit a problem pretty fast that I don’t understand. I haven’t changed the original structure of the auto generated code yet. I got this code to work on the website.
using ServiceReference.ServiceClient wcfClient = new ServiceReference.ServiceClient())
{
string data = wcfClient.GetData(32);
Label1.Text += data;
}
But when I started using this code I got in to some problem.
ServiceReference.Kund kund;
using (ServiceReference.ServiceClient wcfClient = new ServiceReference.ServiceClient())
{
string data = wcfClient.GetDataUsingDataContract(kund);
}
I got the this error. I can’t really see any problem with the data type it’s not a string.
Cannot implicitly convert type ‘Webbshop.ServiceReference.Kund’ to ‘string’
Edit:
[ServiceContract]
public interface IService
{
[OperationContract]
string GetData(int value);
[OperationContract]
Kund GetDataUsingDataContract(Kund kund);
}
[DataContract]
public class Kund
{
int iD;
[DataMember]
public int ID
{
get { return iD; }
set { iD = value; }
}
}
Can you show us the service contract (that
IMyServiceinterface, or whatever it’s called in your case) you have??Typically, the sample apps that the WCF service generates will have one method
GetDatathat returns a string, and a second method that shows how to return a complex data typeHere: the second method – after your alterations – returns a
Kund. Of course, if you call that second method which returns aKund, you cannot just assign your entireKundto a string…. you would have to do something like: