从dotnet客户端调用Java Web服务

时间:2009-09-11 08:36:09

标签: c# java service

当我尝试从C#代码访问Tomcat中托管的Web服务时,我收到这样的错误消息。

There was an error in serializing body of message searchRepositoriesRequest: '
Unable to generate a temporary class (result=1).
error CS0266: Cannot implicitly convert type 'object' to 'object[]'. An explicit
 conversion exists (are you missing a cast?)
error CS0266: Cannot implicitly convert type 'object' to 'object[]'. An explicit
 conversion exists (are you missing a cast?)
error CS0266: Cannot implicitly convert type 'object' to 'object[]'. An explicit
 conversion exists (are you missing a cast?)
'.  Please see InnerException for more details.

有人能帮帮我吗?请参考下面给出的堆栈跟踪。

Server stack trace:
   at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.SerializeBo
dy(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDes
cription messageDescription, Object returnValue, Object[] parameters, Boolean is
Request)
   at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(Xm
lDictionaryWriter writer, MessageVersion version, Object[] parameters, Object re
turnValue, Boolean isRequest)
   at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessag
e.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWri
ter writer)
   at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDict
ionaryWriter writer)
   at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter wr
iter)
   at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writ
er)
   at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message me
ssage, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
   at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.
WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager,
 Int32 messageOffset)
   at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message m
essage)
   at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.SendRequest(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeS
pan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message messag
e, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
   at WSTesting2.SBS.SBSQueryService.searchRepositories(searchRepositoriesReques
t request)
   at WSTesting2.SBS.SBSQueryServiceClient.WSTesting2.SBS.SBSQueryService.search
Repositories(searchRepositoriesRequest request) in E:\Tetsngs\WSTesting2\Service
 References\SBS\Reference.cs:line 2253
   at WSTesting2.SBS.SBSQueryServiceClient.searchRepositories(searchRequest arg0
) in E:\Tetsngs\WSTesting2\Service References\SBS\Reference.cs:line 2259
   at WSTesting2.Program.Main(String[] args) in E:\Tetsngs\WSTesting2\Program.cs
:line 66Press any key to continue . . .

1 个答案:

答案 0 :(得分:0)

我们遇到了同样的问题。我相信你会在wsdl的某个地方找到一个列表列表,即一个元素,其中maxOccurs = unbounded,type是单个元素的序列,maxOccurs = unbounded。

有关此案的另一个案例,请参阅'Error serializing body'. Problem calling Fedex webservice through .NET 3.5

可能的解决方案包括修改wsdl而不使用列表列表(例如,在内部类型中添加虚拟字段),或者按照其他链接上的建议手动编辑生成的代码。

相关问题