I am writing an ios app that talks to the asp.net server by using SOAP web services. one of my web service need to take array of objects. The object definitions are exactly the same on both sides.
Here is what I tried: When I passed just one object as the parameter, the web service worked fine. But as soon as I passed an array of the objects, I got nothing returned. I know the code inside the web service never get called which means the server failed
to read the parameters. The wired thing is that the web service returned nothing so I cannot tell what's wrong(I used to get error message from server showing me the stack trace when I did something wrong in the past).
I am not that familiar with SOAP web services so even though I spent a lot of time on MSDN, I still didn't understand what's wrong. After publish the web service, I accessed it through browser. I copied the whole thing to my iOS app so it should work in theory
but it never did.
Anyway, this is the server side code:
[System.Web.Services.Protocols.SoapRPCMethod]
[WebMethod(EnableSession = true)]
[XMLInclude(typeof(Team))]
[XMLInclude(typeof(Team[]))]
[SoapInclude(typeof(Team))]
[SoapInclude(typeof(Team[]))]
public string testTeamWebService(Team[] teams)
{
// do something here
}
// class definition of Team
[Serializable]
public class Team
{
public int TeamID;
public string TeamName;
}
According to the web service page(.asmx file), here is what I should do to call it:
As I said, I constructed the xml and send it in iOS. I used NSMutableURLRequest object and the constructed xml is exactly the way I mentioned above.
In my other web services, I get object arrays from the server so I know .net can serialize the array. This is the first time that my service need to take an array as a parameter, so I think there must be a way of doing it.
And I got the error message from server:
faultcode: soap:Server
faultstring: System.Web.Services.Protocols.SoapException: Server was unable to process request.---> System.ArgumentException: Object of type 'System.Xml.XmlNode[]' cannot be converted to type 'abc.WebServices.Team[]'.
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
--- End of inner exception stack trace ---
detail:
Please give me some advice if you could. Thanks very much for reading my question.
Hi Peter, Thank you very much for your reply. I read your the old post and did some research. I generally understood that, as you said, I should wrap my object into a xmlnode class. However since I am not very familiar with the SOAP on .net side, I am really
confused of what I should do. Is their a good example I could follow? If not, would you please provide me with more details? Thanks a lot Peter.
Thank you very much for writing the code for me. I tested your code and it worked perfect. I'm not sure what's wrong with my problem yet, but I guess it could be the encoding of the RPC.
I'll try more things to figure out what's the actual problem, but I marked your answer as the correct one.
RayAsInSunsh...
Member
2 Points
3 Posts
asp.net SOAP RPC web method could not read object array parameter
Mar 23, 2012 09:46 PM|LINK
I am writing an ios app that talks to the asp.net server by using SOAP web services. one of my web service need to take array of objects. The object definitions are exactly the same on both sides.
Here is what I tried: When I passed just one object as the parameter, the web service worked fine. But as soon as I passed an array of the objects, I got nothing returned. I know the code inside the web service never get called which means the server failed to read the parameters. The wired thing is that the web service returned nothing so I cannot tell what's wrong(I used to get error message from server showing me the stack trace when I did something wrong in the past).
I am not that familiar with SOAP web services so even though I spent a lot of time on MSDN, I still didn't understand what's wrong. After publish the web service, I accessed it through browser. I copied the whole thing to my iOS app so it should work in theory but it never did.
Anyway, this is the server side code:
[System.Web.Services.Protocols.SoapRPCMethod] [WebMethod(EnableSession = true)] [XMLInclude(typeof(Team))] [XMLInclude(typeof(Team[]))] [SoapInclude(typeof(Team))] [SoapInclude(typeof(Team[]))] public string testTeamWebService(Team[] teams) { // do something here } // class definition of Team [Serializable] public class Team { public int TeamID; public string TeamName; } According to the web service page(.asmx file), here is what I should do to call it:Peter pi - M...
Star
12871 Points
1786 Posts
Re: asp.net SOAP RPC web method could not read object array parameter
Mar 26, 2012 02:34 AM|LINK
Hi,
Try making your object's base class to an XmlNode rather than some custom object (such as Team), please check the following similar post.
http://forums.asp.net/t/1056699.aspx/1
#Data Types Supported by XML Web Services Created Using ASP.NET
http://msdn.microsoft.com/en-us/library/3003scdt.aspx
Regards,
Peter
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
RayAsInSunsh...
Member
2 Points
3 Posts
Re: asp.net SOAP RPC web method could not read object array parameter
Mar 26, 2012 08:24 PM|LINK
Peter pi - M...
Star
12871 Points
1786 Posts
Re: asp.net SOAP RPC web method could not read object array parameter
Mar 27, 2012 03:20 AM|LINK
I created a simple asmx web service which contains only one web method and a class Team, they are as follows:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService3 : System.Web.Services.WebService
{
[WebMethod]
public string testTeamWebService(Team[] teams)
{
return teams[0].TeamName;
}
}
[Serializable]
public class Team
{
public int TeamID;
public string TeamName;
}
and then I used the Fiddler to call this web service by using the following request headers and request body.
Request Headers:
User-Agent: Fiddler
POST /WebService3.asmx HTTP/1.1:
Host: localhost:8776
Content-Type: text/xml; charset=utf-8
Content-Length: 577
SOAPAction: "http://tempuri.org/testTeamWebService"
Request Body:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<testTeamWebService xmlns="http://tempuri.org/">
<teams>
<Team>
<TeamID>1001</TeamID>
<TeamName>webdev</TeamName>
</Team>
<Team>
<TeamID>1002</TeamID>
<TeamName>SQL</TeamName>
</Team>
</teams>
</testTeamWebService>
</soap:Body>
</soap:Envelope>
it can call this web service and return the result success, and didn't encounter your issue.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
RayAsInSunsh...
Member
2 Points
3 Posts
Re: asp.net SOAP RPC web method could not read object array parameter
Mar 27, 2012 03:48 PM|LINK
Hi Peter,
Thank you very much for writing the code for me. I tested your code and it worked perfect. I'm not sure what's wrong with my problem yet, but I guess it could be the encoding of the RPC.
I'll try more things to figure out what's the actual problem, but I marked your answer as the correct one.
Thanks again.