Google Groups จะไม่รองรับโพสต์หรือการสมัครสมาชิก Usenet ใหม่อีกต่อไป โดยคุณจะยังคงดูเนื้อหาเดิมได้อยู่

Serialization problem, using .NET client to access Java (Apache Axis) Web Service

ยอดดู 13 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Dino Chiesa [Microsoft]

ยังไม่อ่าน,
22 เม.ย. 2547 16:16:3122/4/47
ถึง
Try to wrap your Array in an object. In other words, instead of this:
flightPlan[] Method(...) {
}

...do this (in Java/Axis):

public fpArray {
flightPlan[] fp;
}

fpArray Method(...) {
}

In my experience, this works.
Java/AXIS expects the array to be encoded differently than .NET encodes it.


------

Couple of other suggestions:

1. start with the WSDL first. Rather than starting with the Java (server)
implementation and inferring the WSDL, start with the WSDL and generate a
server-side Java/AXIS skeleton. AXIS has a wsdl2java tool for this purpose.
You can do the same thing with "wsdl.exe /server" on the server side.

By doing this you will have a common starting point and will avoid the issue
you originally described.


2. You can use a Java2 collection called Arraylist, rather than Vector, for
your fltPlans, to save yourself some trouble in generating an Array. see
Arraylist.toArray(). (rather than looping)

-D

--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ ElideThis . m i c r o s o f t . c o m

"Archana" <anon...@discussions.microsoft.com> wrote in message
news:4F1C9157-D63A-4693...@microsoft.com...
>
> I get the following exception when my web service returns an array of
objects. The same call works for a single object though. So looks like there
is no problem serializing the object but there seems to be a problem
serializing an array of objects. Any help will be appreciated.
>
>
> Stack Trace:
>
> [InvalidCastException: Cannot assign object of type System.Object[] to an
object of type FPM.FlightPlanManagement.FlightPlan[].]
>
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read37
_searchForFlightsResponse() +435
>
> [InvalidOperationException: There is an error in XML document (23, 29).]
> System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,
String encodingStyle) +415
> System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
+7
>
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClient
Message message, WebResponse response, Stream responseStream, Boolean
asyncCall) +1050
> System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters) +218
>
FPM.FlightPlanManagement.IFlightPlanManagementSystemService.searchForFlights
(String in0, String in1, String in2) in c:\inetpub\wwwroot\fpm\web
references\flightplanmanagement\reference.cs:213
> FPM.SearchOptions.Search_Button_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\fpm\searchoptions.aspx.cs:65
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
>
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
> System.Web.UI.Page.ProcessRequestMain() +1277
>
>
> Related code from .NET proxy class.............................
>
> /// <remarks/>
> [System.Web.Services.Protocols.SoapRpcMethodAttribute("",
RequestNamespace="urn:FPM", ResponseNamespace="urn:FPM")]
> [return:
System.Xml.Serialization.SoapElementAttribute("searchForFlightsReturn")]
> public FlightPlan[] searchForFlights(string in0, string in1,
string in2) {
> object[] results = this.Invoke("searchForFlights", new
object[] {
> in0,
> in1,
> in2});
> return ((FlightPlan[])(results[0]));
> }
>
> [System.Xml.Serialization.SoapTypeAttribute("FlightPlan", "urn:FPM")]
> public class FlightPlan {
>
> /// <remarks/>
> public string flightNo;
>
> /// <remarks/>
> public string pilot;
> }
>
>
> Here is the Java Code....................
>
> public flightplanmanagement.FlightPlan[]
searchForFlights(java.lang.String in0, java.lang.String in1,
java.lang.String in2)
> throws java.rmi.RemoteException
> {
> try
> {
> Class.forName("com.mysql.jdbc.Driver").newInstance();
> java.sql.Connection conn;
> conn =
DriverManager.getConnection("jdbc:mysql://localhost/fpm_test?user=archana");
> String selStmt = "select * from flight_plan;";
> System.out.println("select statement = " + selStmt);
> Statement stmt = conn.createStatement();
> com.mysql.jdbc.ResultSet rs = (com.mysql.jdbc.ResultSet)
> stmt.executeQuery(selStmt);
> Vector fltPlans = new Vector();
> while(rs.next())
> {
> FlightPlan fp = new FlightPlan();
>
> fp.setFlightNo(rs.getString("FLT_NO"));
> fp.setPilot(rs.getString("PILOT"));
> fltPlans.add(fp);
>
> }
> FlightPlan[] fpArray = new FlightPlan[fltPlans.size()];
> // return (FlightPlan[] )fltPlans.toArray(fpArray);
> for(int i = 0; i < fltPlans.size(); i++)
> {
> fpArray[i] = (FlightPlan) fltPlans.get(i);
> }
> return fpArray;
> }
> catch(Exception ex)
> {
> ex.printStackTrace();
> throw new java.rmi.RemoteException(ex.getMessage());
> }
> }


ข้อความใหม่ 0 รายการ