【问题标题】:response produced exception – java client / WCF web service响应产生异常 - java 客户端/WCF Web 服务
【发布时间】:2015-10-12 14:29:37
【问题描述】:

我有一个从 Java 客户端调用的 WCF Web 服务。 Java 客户端使用固定的 WSDL 文件。这意味着我必须操纵我的 Web 服务才能与客户端一起运行。我有不止一种方法,有些方法正在奏效。 如果我发送一个列表作为响应,我会在客户端收到异常。 java客户端的规范是:

<ns2:methodName xmlns:ns2="http://namespace.de">
 <return>
  <element1>2015-10-12T11:41:31+02:00</element1>
  <element2>testText</element2>
  <filename>documentName.pdf</filename>
  <element3>99999</element3>
 </return>
 <return>
  <element1>2015-10-12T11:49:13+02:00</element1>
  <element2>test 2txt</element2>
  <filename>test.txt</filename>
  <element3>99999</element3>
 <return>
</ns2: methodName >

XSD:

<xs:complexType name="methodName">
    <xs:sequence>
      <xs:element name="return" type="tns:dataType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

我尝试了很多替代方法,这里是其中之一。

IService:

<OperationContract(Action:="http://namespace/methodNameRequest", Name:="methodName", ReplyAction:="http://namespace/methodNameResponse")>    
        Function methodName(input As methodName) As methodNameResponse

<MessageContract()>
Public Class methodNameResponse
   <MessageBodyMember(Name:="return", [Namespace]:="")>
   Public result 
End class

没有数据类型,因为有多个响应值,调用返回。

服务:

Public Function methodName(input As methodName) As methodNameResponse Implements IService.methodName

    Dim ListeDataType As New List(Of datatype)
    Dim value As methodNameResponse = New methodNameResponse()
    value.result = ListeDataType
    Return ListeDataType
End Function

肥皂消息:

<methodNameResponse xmlns="http://namespace.de">
 <return xsi:type="q1:ArrayOfdataType" xmlns="" xmlns:q1="http://namespace.de">
   <q1:dataType>
     <q1:element1>2014-03-14T21:00:40</q1: element1>
     <q1:element2> test text </q1: element2>
     <q1:filename >test.txt</q1:filename>
     <q1:element3>99999</q1: element3>
   </q1:dataType>
   <q1:dataType >
     <q1:element1>2014-03-14T21:00:40</q1: element1>
     <q1:element2> test2 text </q1: element2>
     <q1:filename >test2.txt</q1: filename>
     <q1:element3>99999</q1: element3>
   </q1:dataType >
 </return>
</methodNameResponse>

这样我得到了异常:q1:ArrayofDataType 不能被解析为元素“return”的类型定义。我已经尝试了不止一个,但如果我成为解决这种行为的好主意,我很乐意再试一次。谢谢你的建议。

【问题讨论】:

  • 这看起来不像完整的 .wsdl。我想你确实有完整的并且不是试图扭转部分sn-p? svcutil 命令行实用程序应该可以帮助您。 svcutil /language:VB /mc service.wsdl types.xsd 这将为您创建消息契约类型,并希望提供一个工作接口。如果不是,那么您想要的 Web 服务不符合正确的规范,您开始使用自定义调度程序进入高级领域。

标签: java .net web-services wcf


【解决方案1】:

@MattC 谢谢你的提示。它帮助我解决了我的问题。

解决方案:

用

构建界面
SvcUtil.exe /importXmlTypes *.wsdl *.xsd /language:VB 

/importXmlTypes - 我必须使用这个,因为标准调用,因为重复声明“return”而得到一个异常。经过一些更正后,它可以使用以下代码:

IService:

<System.ServiceModel.OperationContractAttribute(Action:="http://namespace/methodNameRequest", ReplyAction:="http://namespace/methodNameResponse"),
     System.ServiceModel.XmlSerializerFormatAttribute()>
    Function methodName(ByVal input As methodName) As <System.ServiceModel.MessageParameterAttribute(Name:="return")> methodNameResponse

<System.Diagnostics.DebuggerStepThroughAttribute(),
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"),
 System.ServiceModel.MessageContractAttribute(WrapperName:="methodName", WrapperNamespace:="http://namespace", IsWrapped:=True)>
Partial Public Class methodNameRequest
    <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="http://namespace", Order:=0),
     System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
    Public element1 As String
…
End class

<System.Diagnostics.DebuggerStepThroughAttribute(),
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"),
 System.ServiceModel.MessageContractAttribute(WrapperName:="methodNameResponse", WrapperNamespace:="http://namespace", IsWrapped:=True)>
Partial Public Class methodNameResponse

    <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="http://namespace", Order:=0),
     System.Xml.Serialization.XmlElementAttribute("return", Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
    Public [return]() As dataType

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal [return]() As dataType)
        MyBase.New()
        Me.[return] = [return]
    End Sub
End Class

服务:

Public Function methodName(input As methodName) As methodNameResponse Implements IService.methodName
…
            Dim ListResponse As New methodNameResponse()
            ListResponse.return = ListeDataType.ToArray
            Return ListResponse 
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    相关资源
    最近更新 更多