为WCF文件上载创建CXF代理客户端

时间:2012-10-23 22:31:14

标签: wcf file-upload cxf

我正在尝试创建一个WCF服务(VS2012中的.Net 4.5),用于文件上传,其他语言的客户端尤其可以使用Java(使用CXF)。我已经从.Net客户端获得了很好的WCF方面,但我在CXF方面遇到了一些问题。

当我尝试从WSDL通过Eclipse(4.2 / Juno)在CXF中生成代理时,我遇到了一个阻止代理被创建的异常:

wsdl2java -client -d C:\Users\Ryan\workspace\WcfProxy\.cxftmp/src -classdir C:\Users\Ryan\workspace\WcfProxy\build\classes -p http://tempuri.org/=org.tempuri -impl -validate -exsh false -dns true -dex true -wsdlLocation http://localhost:10186/UploadFile.svc?wsdl -verbose -defaultValues -fe jaxws -db jaxb -wv 1.1 http://localhost:10186/UploadFile.svc?wsdl
wsdl2java - Apache CXF 2.7.0


WSDLToJava Error: Schema Error : src-resolve: Cannot resolve the name 'ns0:StreamBody' to a(n) 'type definition' component.

org.apache.cxf.tools.common.ToolException: Schema Error : src-resolve: Cannot resolve the name 'ns0:StreamBody' to a(n) 'type definition' component.
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.validateSchema(JAXBDataBinding.java:914)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.addSchemas(JAXBDataBinding.java:586)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:392)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.generateTypes(WSDLToJavaContainer.java:603)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:248)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:142)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:300)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:184)
Caused by: org.xml.sax.SAXParseException; src-resolve: Cannot resolve the name 'ns0:StreamBody' to a(n) 'type definition' component.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseLocalElements(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.validateSchema(JAXBDataBinding.java:909)
... 10 more

我的WCF服务合同如下:

<ServiceContract()>
Public Interface IUploadFile

    <OperationContract()>
    Sub UploadFile(ByVal remoteFile As RemoteFile)

    <OperationContract()>
    Function DownloadFile() As RemoteFile

End Interface

我的WCF邮件合同(RemoteFile)如下:

<MessageContract()> _
Public Class RemoteFile
    Implements IDisposable

    <MessageHeader(MustUnderstand:=True)> _
    Public FileName As String

    <MessageHeader(MustUnderstand:=True)> _
    Public Length As Long

    <MessageBodyMember(Order:=1)> _
    Public FileByteStream As System.IO.Stream

    Public Sub Dispose() Implements IDisposable.Dispose
        If FileByteStream IsNot Nothing Then
            FileByteStream.Close()
            FileByteStream = Nothing
        End If
    End Sub
End Class

我的WCF服务配置如下:

...
<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="FileTransferServicesBinding"
        transferMode="Streamed"
        messageEncoding="Mtom"
        maxReceivedMessageSize="10067108864">
      </binding>
    </basicHttpBinding>
  </bindings>
  <services>
    <service behaviorConfiguration="UploadServiceBehavior" name="Server.UploadFile">
      <endpoint address=""
            binding="basicHttpBinding"
            bindingConfiguration="FileTransferServicesBinding"
            contract="Server.IUploadFile" />
    </service>
  </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="UploadServiceBehavior">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
...

我的WSDL如下:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="UploadFile" targetNamespace="http://tempuri.org/">
<wsp:Policy wsu:Id="BasicHttpBinding_IUploadFile_policy">
    <wsp:ExactlyOne>
        <wsp:All>
            <wsoma:OptimizedMimeSerialization/>
        </wsp:All>
    </wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
        <xsd:import schemaLocation="http://localhost:10186/UploadFile.svc?xsd=xsd1" namespace="http://tempuri.org/"/>
        <xsd:import schemaLocation="http://localhost:10186/UploadFile.svc?xsd=xsd0" namespace="http://schemas.microsoft.com/Message"/>
        <xsd:import schemaLocation="http://localhost:10186/UploadFile.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
    </xsd:schema>
</wsdl:types>
<wsdl:message name="RemoteFile">
    <wsdl:part name="parameters" element="tns:RemoteFile"/>
</wsdl:message>
<wsdl:message name="RemoteFile_Headers">
    <wsdl:part name="FileName" element="tns:FileName"/>
    <wsdl:part name="Length" element="tns:Length"/>
</wsdl:message>
<wsdl:message name="IUploadFile_DownloadFile_InputMessage"/>
<wsdl:portType name="IUploadFile">
    <wsdl:operation name="UploadFile">
        <wsdl:input wsaw:Action="http://tempuri.org/IUploadFile/UploadFile" name="RemoteFile" message="tns:RemoteFile"/>
    </wsdl:operation>
    <wsdl:operation name="DownloadFile">
        <wsdl:input wsaw:Action="http://tempuri.org/IUploadFile/DownloadFile" message="tns:IUploadFile_DownloadFile_InputMessage"/>
        <wsdl:output wsaw:Action="http://tempuri.org/IUploadFile/DownloadFileResponse" name="RemoteFile" message="tns:RemoteFile"/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IUploadFile" type="tns:IUploadFile">
    <wsp:PolicyReference URI="#BasicHttpBinding_IUploadFile_policy"/>
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="UploadFile">
        <soap:operation soapAction="http://tempuri.org/IUploadFile/UploadFile" style="document"/>
        <wsdl:input name="RemoteFile">
            <soap:header message="tns:RemoteFile_Headers" part="FileName" use="literal"/>
            <soap:header message="tns:RemoteFile_Headers" part="Length" use="literal"/>
            <soap:body use="literal"/>
        </wsdl:input>
    </wsdl:operation>
    <wsdl:operation name="DownloadFile">
        <soap:operation soapAction="http://tempuri.org/IUploadFile/DownloadFile" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="RemoteFile">
            <soap:header message="tns:RemoteFile_Headers" part="FileName" use="literal"/>
            <soap:header message="tns:RemoteFile_Headers" part="Length" use="literal"/>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="UploadFile">
    <wsdl:port name="BasicHttpBinding_IUploadFile" binding="tns:BasicHttpBinding_IUploadFile">
        <soap:address location="http://localhost:10186/UploadFile.svc"/>
    </wsdl:port>
</wsdl:service>
</wsdl:definitions>

显然,异常表明它在创建消息的流体类型时遇到问题,但有没有人看到我做错了什么或需要更改才能为此WCF服务生成CXF代理?

编辑将WSDL添加到原始帖子。

0 个答案:

没有答案