I am trying to implement REST service in my C# application to communicate with Android client. I struggle with C# part.
I followed this article: http://msdn.microsoft.com/en-us/library/bb412178
This is how I run my service:
WebServiceHost host = new WebServiceHost(typeof(RestService), new Uri("http://localhost:8000/"));
ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IRestService), new WebHttpBinding(), "");
host.Open();
Very like in article linked above I have IRestService interface and RestService with methods EchoWithGet(string s) and EchoWithPost which i dont use and I will not talk about it more. I want to return UserClientInfo class which is the cause of problem I will describe later.
[ServiceContract]
interface IRestService
{
[OperationContract]
[WebGet]
UserClientInfo EchoWithGet(string s);
}
Here is implementation of EchoWithGet(…). It connects to another service and calls UserLog which should return UserClientInfo.
public UserClientInfo EchoWithGet(string s)
{
service = (IService)Activator.GetObject(typeof(IService), "tcp://127.0.0.1:7878/" + "Service");
service.UserLog("username", "password", out uci);
return uci;
}
UserClientInfo is quite complex object. I am not sure if I can return it by service. It is struct containing another structures inside which contains another structures.
[Serializable]
public struct UserClientInfo
{
public ulong ClientId;
public DatabaseManager DBManager;
public string DisplayedName;
public ChISDispositions Dispositions;
public RegistrationInfo RegistrationInfo;
public uint Right1;
public uint Right2;
public uint Right3;
public uint Right4;
public string SessionId;
public string UserId;
}
When I run my service and point my browser to http://localhost:8000/EchoWithGet?s=teststring I get Connection Interupted error. Firebug is showing status Aborted on network tab. Service somehow crashes. I can debug it and see that UserLog() retunrs uci object well and service returns it but somewhere between browser and service it fails.
I tried to return completly new object:
UserClientInfo uci = new UserClientInfo();
That works and returns xml with plain object.
Is there something I do wrong?
Are there some limitation of services I should know about?
Is there any log where I could see whats wrong?
Thanks for any answer.
The problem was in complex some parts of that complex object. Solution was to convert it to DTO.