.NET Web服务和java.io.NotSerializableException [英] .NET Web Service and java.io.NotSerializableException

查看:58
本文介绍了.NET Web服务和java.io.NotSerializableException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个.NET 2.0 Web服务,其方法接受一个类作为参数。
参数类定义为[Serializable()]属性,如

[序列化()]
公共类参数
{

//成员



在我的Java(Netbeans 6.5.1)客户端中,我导入了Web Service的wsdl。

在Java客户端中,我调用.NET Web Service如下所示

试试{// Call Web服务操作

参数param = new Parameter();
param.setVariable(" Hello WS!");
Dispatch< Source> sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName,Source.class,Service.Mode.PAYLOAD);
源结果= sourceDispatch.invoke(new StreamSource(new ByteArrayInputStream(getBytes(param))));
} catch(例外情况)
{
System.out.println(ex.getMessage());

public字节[] getBytes(Object obj)抛出java.io.IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
oos.flush();
oos.close();
bos.close();
byte [] data = bos.toByteArray();
返回数据;
当客户端尝试调用和序列化Parameter类实例时,我在getBytes方法中得到了java.io.NotSerializableException。

我应该如何在.NET Web Service中声明参数类可序列化以便Java了解它?

或者还有其他方法吗?

最诚挚的问候

Michael

Hello,

I have a .NET 2.0 Web Service with a method that accepts a class as an parameter.
Parameter class is defined with [Serializable()] attribute like

[Serializable()]
public class Parameter
{

 // members

}

In my Java (Netbeans 6.5.1) client I have imported Web Service's wsdl.

In Java client I call .NET Web Service like below

 try { // Call Web Service Operation

            Parameter param = new Parameter();
            param.setVariable("Hello WS!");
            Dispatch<Source> sourceDispatch = null;
            sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
            Source result = sourceDispatch.invoke(new StreamSource(new ByteArrayInputStream(getBytes(param))));
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }

    public byte[] getBytes(Object obj) throws java.io.IOException{
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          ObjectOutputStream oos = new ObjectOutputStream(bos);
          oos.writeObject(obj);
          oos.flush();
          oos.close();
          bos.close();
          byte [] data = bos.toByteArray();
          return data;
    }


When client tries to invoke and serialize Parameter class instance I get
java.io.NotSerializableException in getBytes method.

How should I declare Parameter class in .NET Web Service serializable
so that Java understands it?

Or is there any other way to do this?

Best Regards

Michael

推荐答案

首先,[Serializable]并不会真正影响Web服务参数的序列化方式。

其次,请从Java发布完整的异常。它可能会说些有用的东西。除其他事项外,请准确说明getBytes中发生异常的位置。

最后,您应该问一下了解Java的人的问题。为了让Java了解.NET中的数据,您无需做任何特别的事情。特别是,从代码中可以看出,您已经创建了一个Parameter实例,显然,Java确实理解了它。

First of all, [Serializable] doesn't really affect how a web service parameter is serialized.

Second, please post the entire exception from Java. It may say something helpful. Among other things, please say exactly where in getBytes the exception occurs.

Finally, you should really ask this question of people who understand Java. There's nothing special you need to do in order for Java to understand data from .NET.  In particular, it appears from your code that you have already created an instance of Parameter, so apparently, Java does understand it.


这篇关于.NET Web服务和java.io.NotSerializableException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆