I am making a webservice (can’t shift to wcf due to .net req). My WebServiceRequest Class has list of other classes in it. I get below error when I try to compile code:
request.List = list;
Cannot implicitly convert type
‘System.Collections.Generic.List’ to
‘ServiceReference1.foo[]’
This error goes away when i do request.List = list.ToArray();
but when i run the code i get this exception:
An error occurred while receiving the HTTP response to
http://localhost:60380/fooService/fooService.asmx. 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.
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.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs) 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
ServiceReference1.testpingtestSoap.Calculatetestping(CalculatetestpingRequest1
request) at
ServiceReference1.testpingtestSoapClient.ServiceReference1.testpingtestSoap.Calculatetestping(CalculatetestpingRequest1
request) in c:\Users\User\AppData\Local\Temp\Temporary ASP.NET
Files\test\2e05987f\91110734\App_WebReferences.rwmro5zd.0.cs:line 855
at
ServiceReference1.testpingtestSoapClient.Calculatetestping(CalculatetestpingRequest
_request) in c:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\test\2e05987f\91110734\App_WebReferences.rwmro5zd.0.cs:line 862
at testCost2.Calculatetestping() in
c:\Users\User\Desktop\test\InfoSystem\testping\testCost2.aspx.cs:line
203 at testCost2.Submit_Go(Object sender, EventArgs e) in
c:\Users\User\Desktop\test\InfoSystem\testping\testCost2.aspx.cs:line
148 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) at
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Edit 1:
Request & Responce Classes of Web Service
public class Item
{
public List<string> Composites { get; set; }
public string Composites_List { get { return string.Join(", ", Composites.ToArray()); } }
public List<px> pxes { get; set; }
public List<ox> oxes { get; set; }
public List<MethodCalculationType> MethodCalculationTypes { get; set; }
public ShippingItem() { }
public void ShippingItemFill(string sku, int quantity)
{
\\this method is just written to avoid parameterless constructor error
}
public static ItemComparison = delegateItem item1, Item item2) { return item1.Area.CompareTo(item2.Area); };
}
public class Request
{
public List<Item> ItemList;
public bool showAllRatesField;
public bool m_Ignore;
public string pTextField;
public decimal TotalField;
}
public class Responce
{
public od [] ods;
}
Found the problem, you can use as many
Lists<>in your parameters to webservice as you want, here’s what i found; in case someone needs it:1.Enabled dignostics on server by adding below to web.config on server side2.When Http Exception occured; in log file it wroteerror reading or writing a variablei looked up that variable in webservice code and that variable wasinternal, removed internal keyword from that variable and the code started working.Turns out
soapneeds paramerters to be serialized so any varaible in your custom parameter class should be public read/write. as mentioned by John Saunders here