I am Using WCF service to implement my web-service I have problem when I try to call my function which takes URL as input parameter and returns an object class which was defined by me.
public class Service: IService<br>
{
public ClassWS My_Stores(String URL)
{
try
{
//ClassWS is a class which has other classes like address() defined by me
ClassWS My_WS = new ClassWS ();
return ClsStore.My_Stores(URL);
}
catch (Exception ex)
{}
}
}
[DataContract]
public class ClassWS
{
[DataMember]
public granularity Granularity;
[DataMember]
public address[] Address = new address[5];
[DataMember]
public Store[] Stores;
[DataMember]
public int Status;
public ClassWS My_Stores(String URL)
{
ClassQuery q = new ClassQuery();
return (sq.PopulateStores(URL));
}
}
I have included every class defined by me in the DataContract as I have done in the above class. I am getting the error below mentioned when I am trying to return ClassWS
but does not have any error with return Store[] or Address[]
I am getting the error. The error is not returned in the service code but occurs when the retuning the value to proxy.
The underlying connection was closed: The connection was closed unexpectedly. 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 IFindStore.My_Stores(String URL) at FindStoreClient.My_Stores(String URL) Inner Exception: The underlying connection w开发者_运维技巧as closed: The connection was closed unexpectedly. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
I would like to know how to get a datacontract for a class which has another classes as their fields.
Should I write the object to a stream using datacontractserialzer (even though data-contract uses datacontractserializer). Should I be using XmlSerializer?
Thanks in advance
In general, as long as you are having DataContract + Datamembers for all relevant classes, which you already seem to have, that is all that is needed for the DataContractSerializer to serialize them.
The following
The underlying connection was closed: The connection was closed unexpectedly.
Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.
ProcessGetResponseWebException (WebException .....
is a generic exception that you will commonly see if there is an unhandled exception in your service which is causing the remote connection to be closed.
It is not necessarily something to do with the serialization of your classes.
I would suggest that you step-into your service method while debugging as that will tell you exactly what exception is being thrown and why!
精彩评论