我有一个我在Tomcat 7.0.54上的localhost上部署的Web服务,其中包含以下wsdl文件:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="SRW" targetNamespace="http://www.loc.gov/zing/srw/srwabosi/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:srw-bindings="http://www.loc.gov/zing/srw/srw-bindings/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
<import namespace="http://www.loc.gov/zing/srw/srw-bindings/" location="srw-bindings.wsdl">
</import>
<service name="SRWABOSI">
<port name="SRW" binding="srw-bindings:SRW-SoapBinding">
<soap:address location="http://localhost:8080/abosi/services/SRW"/>
</port>
</service>
</definitions>
和srw-bindings.wsdl
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- edited with XMLSpy v2006 sp1 U (http://www.altova.com) by virtual (EMBRACE) --><!-- ZiNG SRU/SRW WSDL Specification --><!-- Version 1.1 --><!-- 6 October 2004 --><definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:srw-interfaces="http://www.loc.gov/zing/srw/interfaces/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SRW" targetNamespace="http://www.loc.gov/zing/srw/srw-bindings/">
<import location="srw-ports.wsdl" namespace="http://www.loc.gov/zing/srw/interfaces/"/>
<binding name="SRW-SoapBinding" type="srw-interfaces:SRWPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<!-- .... -->
<operation name="DownloadOperation">
<soap:operation style="rpc"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<mime:multipartRelated>
<mime:part name="body">
<soap:body parts="fileName" use="literal"/>
</mime:part>
<mime:part name="attach">
<mime:content part="file" type="application/octet-stream"/>
</mime:part>
<mime:part name="sessionKey">
<mime:content part="sessionKey" type="application/octet-stream"/>
</mime:part>
</mime:multipartRelated>
</output>
</operation>
</binding>
<binding name="Explain-HTTPGetBinding" type="srw-interfaces:ExplainPort">
<http:binding verb="GET"/>
<operation name="ExplainOperation">
<http:operation location="?operation=explain"/>
<input>
<http:urlEncoded/>
</input>
<output>
<mime:mimeXml part="body"/>
</output>
</operation>
</binding>
<binding name="Explain-HTTPGetRootBinding" type="srw-interfaces:ExplainPort">
<http:binding verb="GET"/>
<operation name="ExplainOperation">
<http:operation location="?operation=explain"/>
<input>
<http:urlEncoded/>
</input>
<output>
<mime:mimeXml part="body"/>
</output>
</operation>
</binding>
<binding name="Explain-SoapBinding" type="srw-interfaces:ExplainPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="ExplainOperation">
<soap:operation style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
</definitions>
在tomcat上部署我的应用后,我使用wsdl2java
使用以下命令生成客户端:
wsdl2java -d wsdl2java_test1 -V -client -impl http://localhost:8080/abosi/services/SRW\?wsdl
然后我的界面代码看起来像这样(重要的部分是downloadOperation
)
@WebService(targetNamespace = "http://www.loc.gov/zing/srw/interfaces/", name = "SRWPort")
@XmlSeeAlso({gov.loc.zing.srw.ObjectFactory.class, gov.loc.zing.cql.xcql.ObjectFactory.class, gov.loc.zing.srw.diagnostic.ObjectFactory.class, org.w3._2001._04.xmlenc.ObjectFactory.class, org.w3._2000._09.xmldsig.ObjectFactory.class})
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface SRWPort {
@WebResult(name = "body", targetNamespace = "http://www.loc.gov/zing/srw/interfaces/", partName = "body")
// ...
@WebMethod(operationName = "DownloadOperation")
public void downloadOperation(
@WebParam(partName = "recordId", name = "recordId")
java.lang.String recordId,
@WebParam(partName = "library", name = "library")
java.lang.String library,
@WebParam(partName = "publicKey", name = "publicKey")
org.w3._2000._09.xmldsig.KeyInfoType publicKey,
@WebParam(partName = "fileName", mode = WebParam.Mode.OUT, name = "fileName")
javax.xml.ws.Holder<java.lang.String> fileName,
@WebParam(partName = "file", mode = WebParam.Mode.OUT, name = "file")
javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedDataType> file,
@WebParam(partName = "sessionKey", mode = WebParam.Mode.OUT, name = "sessionKey")
javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedKeyType> sessionKey
);
}
我尝试使用以下代码启动客户端:
package gov.loc.zing.srw.interfaces;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import gov.loc.zing.srw.srwabosi.SRWABOSI;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
public final class SRWPort_SRW_Client {
private static final QName SERVICE_NAME = new QName("http://www.loc.gov/zing/srw/srwabosi/", "SRWABOSI");
private SRWPort_SRW_Client() {}
public static void main(String args[]) throws java.lang.Exception {
URL wsdlURL = SRWABOSI.WSDL_LOCATION;
if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
SRWABOSI ss = new SRWABOSI(wsdlURL, SERVICE_NAME);
SRWPort port = ss.getSRW();
{
System.out.println("Invoking downloadOperation...");
java.lang.String _downloadOperation_recordId = "";
java.lang.String _downloadOperation_library = "";
org.w3._2000._09.xmldsig.KeyInfoType _downloadOperation_publicKey = null;
javax.xml.ws.Holder<java.lang.String> _downloadOperation_fileName = new javax.xml.ws.Holder<java.lang.String>();
javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedDataType> _downloadOperation_file = new javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedDataType>();
javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedKeyType> _downloadOperation_sessionKey = new javax.xml.ws.Holder<org.w3._2001._04.xmlenc.EncryptedKeyType>();
port.downloadOperation(_downloadOperation_recordId, _downloadOperation_library, _downloadOperation_publicKey, _downloadOperation_fileName, _downloadOperation_file, _downloadOperation_sessionKey);
System.out.println("downloadOperation._downloadOperation_fileName=" + _downloadOperation_fileName.value);
System.out.println("downloadOperation._downloadOperation_file=" + _downloadOperation_file.value);
System.out.println("downloadOperation._downloadOperation_sessionKey=" + _downloadOperation_sessionKey.value);
}
System.exit(0);
}
}
但是我收到了这个错误:
Exception in thread "main" java.lang.UnsupportedOperationException: Unexpected Attachment type =class org.w3._2001._04.xmlenc.EncryptedDataType
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$AttachmentBuilder.createAttachmentBuilder(ResponseBuilder.java:237)
at com.sun.xml.internal.ws.client.sei.SEIMethodHandler.buildResponseBuilder(SEIMethodHandler.java:173)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.<init>(SyncMethodHandler.java:74)
at com.sun.xml.internal.ws.client.sei.SEIStub.initMethodHandlers(SEIStub.java:88)
at com.sun.xml.internal.ws.client.sei.SEIStub.<init>(SEIStub.java:78)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:590)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:330)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:312)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:294)
at javax.xml.ws.Service.getPort(Service.java:119)
at gov.loc.zing.srw.srwabosi.SRWABOSI.getSRW(SRWABOSI.java:79)
at gov.loc.zing.srw.interfaces.SRWPort_SRW_Client.main(SRWPort_SRW_Client.java:51)
答案 0 :(得分:0)
问题是(我认为因为之后我能够成功调用我的网络服务)没有面对项目没有
在eclipse中应用此更改后,我能够成功调用我的服务方法。