java webservice开发接口,基于xml格式的数据交换

dragon-loong 2017-04-22 02:25:01
公司要求另一家公司进行接口对接,对方使用的是.Net开发的,而他们所开发的接口要求使用xml格式的数据交换请求,请问一下如何使用webservice来,来开发这个
...全文
3341 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianfang 2017-04-24
  • 打赏
  • 举报
回复
贴wsdl 给你代码
dragon-loong 2017-04-24
  • 打赏
  • 举报
回复
对方提供的wsdl当中的request对象存在关联,直接添加似乎行不通
dragon-loong 2017-04-24
  • 打赏
  • 举报
回复
我使用的是axis来进行解析的,对方提供了wsdl,但是现在遇到了一个问题,对方提供的wsdl: <xs:complexType name="process"> <xs:sequence> <xs:element minOccurs="0" name="request" type="tns:request"/> </xs:sequence> </xs:complexType> <xs:complexType name="request"> <xs:sequence> <xs:element minOccurs="0" name="brNo" type="xs:string"/> <xs:element minOccurs="0" name="content" type="xs:string"/> <xs:element minOccurs="0" name="reqDate" type="xs:string"/> <xs:element minOccurs="0" name="reqSerial" type="xs:string"/> <xs:element minOccurs="0" name="reqTime" type="xs:string"/> <xs:element minOccurs="0" name="token" type="xs:string"/> <xs:element minOccurs="0" name="txCode" type="xs:string"/> </xs:sequence> </xs:complexType> 下面是我的: Service service = new Service(); Object[] object = new Object[1]; object[0] = a; Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL( "http://10.7.101.39/mfs/services/creditService?wsdl")); QName qn = new QName(nameSpace, "process");// 第一个参数名字空间URI,第二个参数本地部分,注意这两部分在server-config.wsdd文件中标签beanMapping配置 call.setOperationName(new QName(nameSpace, method)); call.setSOAPActionURI(""); // 设置返回值类型为String的方法 call.setReturnType(XMLType.SOAP_STRING); call.addParameter(new QName("request"), XMLType.SOAP_STRING, ParameterMode.INOUT); // 这里的name对应参数名称 call.setUseSOAPAction(true); String retVal1 = (String) call.invoke(object); System.out.println(retVal1); 这样只写缺抛出了异常: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize. 请问一下这个异常应当如何解决难!!!
tianfang 2017-04-24
  • 打赏
  • 举报
回复
如果有wsdl,就一定不要自己解析xml,那是soap协议报文,java的ws框架会自动解析
tianfang 2017-04-24
  • 打赏
  • 举报
回复
没什么难度啊 拿到wsdl,生成java客户端, 接口对象赋值,调用webservice 联调
dragon-loong 2017-04-24
  • 打赏
  • 举报
回复
顶贴!!!!!!
tianfang 2017-04-24
  • 打赏
  • 举报
回复
依赖的jar

		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>mail</artifactId>
			<version>1.4.7</version>
		</dependency>
		<dependency>
			<groupId>javax.activation</groupId>
			<artifactId>activation</artifactId>
			<version>1.1.1</version>
		</dependency>

tianfang 2017-04-24
  • 打赏
  • 举报
回复
使用eclipse生成客户端对象

import java.rmi.RemoteException;

import app.creditapp.inf.ws.InfWsProcessProxy;
import app.creditapp.inf.ws.Request;
import app.creditapp.inf.ws.Response;

public class Demo {

	public static void main(String[] args) {
		
		InfWsProcessProxy proxy=new InfWsProcessProxy();
		proxy.setEndpoint("http://10.7.101.39/mfs/services/creditService");
		
		Request request=new Request();
		
		request.setBrNo("");
		request.setReqDate("reqDate");
		
		Response response=new Response();
		try {
			response=proxy.process(request);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		System.out.print(response.getContent());
	}
}

dragon-loong 2017-04-24
  • 打赏
  • 举报
回复
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.inf.creditapp.app/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="InfWsProcessService" targetNamespace="http://ws.inf.creditapp.app/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws.inf.creditapp.app/" elementFormDefault="unqualified" targetNamespace="http://ws.inf.creditapp.app/" version="1.0"> <xs:element name="process" type="tns:process"/> <xs:element name="processResponse" type="tns:processResponse"/> <xs:complexType name="process"> <xs:sequence> <xs:element minOccurs="0" name="request" type="tns:request"/> </xs:sequence> </xs:complexType> <xs:complexType name="request"> <xs:sequence> <xs:element minOccurs="0" name="brNo" type="xs:string"/> <xs:element minOccurs="0" name="content" type="xs:string"/> <xs:element minOccurs="0" name="reqDate" type="xs:string"/> <xs:element minOccurs="0" name="reqSerial" type="xs:string"/> <xs:element minOccurs="0" name="reqTime" type="xs:string"/> <xs:element minOccurs="0" name="token" type="xs:string"/> <xs:element minOccurs="0" name="txCode" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="processResponse"> <xs:sequence> <xs:element minOccurs="0" name="response" type="tns:response"/> </xs:sequence> </xs:complexType> <xs:complexType name="response"> <xs:sequence> <xs:element minOccurs="0" name="content" type="xs:string"/> <xs:element minOccurs="0" name="respCode" type="xs:string"/> <xs:element minOccurs="0" name="respDesc" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> <wsdl:message name="processResponse"> <wsdl:part element="tns:processResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="process"> <wsdl:part element="tns:process" name="parameters"></wsdl:part> </wsdl:message> <wsdl:portType name="InfWsProcess"> <wsdl:operation name="process"> <wsdl:input message="tns:process" name="process"></wsdl:input> <wsdl:output message="tns:processResponse" name="processResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="InfWsProcessServiceSoapBinding" type="tns:InfWsProcess"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="process"> <soap:operation soapAction="" style="document"/> <wsdl:input name="process"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="processResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="InfWsProcessService"> <wsdl:port binding="tns:InfWsProcessServiceSoapBinding" name="InfWsProcessPort"> <soap:address location="http://10.7.101.39:80/mfs/services/creditService"/> </wsdl:port> </wsdl:service> </wsdl:definitions> 需要调用的方法是<xs:complexType name="process">这个
dragon-loong 2017-04-22
  • 打赏
  • 举报
回复
希望通过java调用.net webservice 对方的webservice当中只提供了一个方法给我们,除此之外没有任何其他方法,这种应该如何做难,以前没有做过
李德胜1995 2017-04-22
  • 打赏
  • 举报
回复
参考一下http://blog.csdn.net/hu_shengyang/article/details/38384597

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧