2015-10-12 55 views
0

我有一个WCF Web服务谁从Java客户端调用。 Java客户端使用固定的WSDL文件。这意味着我必须操纵我的Web服务来与客户端一起运行。我有不止一种方法,有些正在工作。 我得到客户端的异常,如果我发送一个列表作为回应。从Java客户端的规格是:响应产生异常 - java客户端/ WCF网络服务

<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 

soapMesssage:

<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不能被解析为一个类型定义为元素 “回报”。我尝试过不止一次,但我很乐意再次尝试,如果我成为解决此行为的好主意。谢谢你的建议。

+1

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

回答

0

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

解决方案:

建立与

SvcUtil.exe /importXmlTypes *.wsdl *.xsd /language:VB 

/importXmlTypes接口 - 这我都用,因为标准的电话,得到一个例外,因为重复的声明“回归”的。一些更正后,它的工作原理与此代码:

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