繁体   English   中英

响应产生的异常– Java客户端/ WCF Web服务

[英]response produced exception – java client / WCF web service

我有一个从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不能解析为元素“返回”的类型定义。 我已经尝试了不止一次,但是如果我成为解决此问题的好主意,我很乐意再次尝试。 谢谢你的建议。

@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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM