跨平台问题:用C#控制台调用J2EE Web Service时,将对象数组序列化传递至Web Service中时,无法正常序列化,也就不能生成Soap包,怎么解
首先我在Web Application Server 中部署了一个J2EE Web Services包,名称是“WeatherForcastEjb”,然后,我用。Net做了一个控制台,用来调用该服务,在添加完Web引用生成代理类“myProxyClass.cs”后,我在控制台主程序中向Web Service传递对象数组,但是就在将对象数组序列化成XML文件,生成Soap包时,抛出异常,“处于状态 Epilog 的标记 StartElement 将导致无效的 XML 文档。”
myProxyClass.cs:
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="serviceLocationSoapBinding", Namespace="http://shouxin.webservices.onceas.com")]
[System.Xml.Serialization.SoapIncludeAttribute(typeof(WeatherInfo))]
[System.Xml.Serialization.SoapIncludeAttribute(typeof(WeatherReq))]
public class WeatherForecastPortService : System.Web.Services.Protocols.SoapHttpClientProtocol {
/// <remarks/>
public WeatherForecastPortService() {
this.Url = "http://133.133.133.237:8080/ws4ee/services/WeatherForecastTest";
}
/// <remarks/>
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://shouxin.webservices.onceas.com", ResponseNamespace="http://shouxin.webservices.onceas.com")]
[return: System.Xml.Serialization.SoapElementAttribute("getWeatherInfoReturn")]
public WeatherInfo[] getWeatherInfo(WeatherReq[] in0) {
object[] results=new object[in0.Length];
try
{
results = this.Invoke("getWeatherInfo", new object[] {
in0});
}
catch(Exception e) //代码就在这里抛出异常 {
System.Console.WriteLine(e.StackTrace.ToString());
}
return ((WeatherInfo[])(results[0]));
}
/// <remarks/>
public System.IAsyncResult BegingetWeatherInfo(WeatherReq[] in0, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("getWeatherInfo", new object[] {
in0}, callback, asyncState);
}
/// <remarks/>
public WeatherInfo[] EndgetWeatherInfo(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((WeatherInfo[])(results[0]));
}
}
/// <remarks/>
[System.Xml.Serialization.SoapTypeAttribute("WeatherReq", "http://shouxin.webservices.onceas.com")]
//[Serializable]
//[SoapElement]
public class WeatherReq {
/// <remarks/>
public string location;
/// <remarks/>
public System.DateTime date;
}
/// <remarks/>
[System.Xml.Serialization.SoapTypeAttribute("WeatherInfo", "http://shouxin.webservices.onceas.com")]
public class WeatherInfo {
/// <remarks/>
public string location;
/// <remarks/>
public System.DateTime date;
/// <remarks/>
public System.Single temperature;
/// <remarks/>
public System.Single humidity;
/// <remarks/>
public int wind;
/// <remarks/>
public System.Single barometricPressure;
}
异常为:“javax.xml.rpc.JAXRPCException: org.xml.sax.SAXException: No deserializer defined for array type {http://shouxin.webservices.onceas.com}WeatherReq”
Console主程序代码如下:
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
WeatherForecastPortService refe=new WeatherForecastPortService();
WeatherReq[] req=new WeatherReq[3];
WeatherInfo[] info=new WeatherInfo[3];
for(int i=0;i<3;i++)
{
info[i]=new WeatherInfo();
req[i]=new WeatherReq();
}
req[0].location="北京";
req[0].date=new System.DateTime(2001,4,5);
req[1].date=new System.DateTime(2003,8,5);
req[1].location="上海";
req[2].date=new System.DateTime(2005,1,1);
req[2].location="广州";
info=refe.getWeatherInfo(req);
}
}
请问高手怎么解决?
后来我又在myProxyClass.cs中添加了反序列化的操作,这时在同一个地方又抛出“"处于状态 Epilog 的标记 StartElement 将导致无效的 XML 文档。"”的异常?
点搞啊?各位高手,高分求助