怎么写webservice接口

1. webservice接口怎么写 以java为例:ava调用WebService可以直接使用Apache提供的axis.jar自己编写代码,或者利用Eclipse自动生成WebService Client代码,利用其中的Proxy类进行调用 。
理论上是一样的,只不过用Eclipse自动生成代码省事些 。1、编写代码方式:package com.yudun.test;import java.rmi.RemoteException;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.message.PrefixedQName;import org.apache.axis.message.SOAPHeaderElement;import com.cezanne.golden.user.Exception;import com.cezanne.golden.user.UserManagerServiceProxy;import javax.xml.namespace.QName;import java.net.MalformedURLException;import javax.xml.rpc.ServiceException;import javax.xml.soap.Name;import javax.xml.soap.SOAPException;public class testWebService {public static String getResult() throws ServiceException, MalformedURLException, RemoteException, SOAPException { //标识Web Service的具体路径 String endpoint = "WebService服务地址"; // 创建 Service实例 Service service = new Service(); // 通过Service实例创建Call的实例 Call call = (Call) service.createCall(); //将Web Service的服务路径加入到call实例之中. call.setTargetEndpointAddress( new java.net.URL(endpoint) );//为Call设置服务的位置 // 由于需要认证,故需要设置调用的SOAP头信息 。
Name headerName = new PrefixedQName( new QName("发布的wsdl里的targetNamespace里的url", "string_itemName") ); org.apache.axis.message.SOAPHeaderElement header = new SOAPHeaderElement(headerName); header.addTextNode( "blablabla" ); call.addHeader(header);// SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("发布的wsdl里的targetNamespace里的url", "SoapHeader"); // soapHeaderElement.setNamespaceURI("发布的wsdl里的targetNamespace里的url"); // try // { // soapHeaderElement.addChildElement("string_itemName").setValue("blablabla"); // } // catch (SOAPException e) // { // e.printStackTrace(); // } // call.addHeader(soapHeaderElement); //调用Web Service的方法 org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param; oper = new org.apache.axis.description.OperationDesc(); oper.setName("opName"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "arg0"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(".yudun.test;import java.rmi.RemoteException;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis.message.PrefixedQName;import org.apache.axis.message.SOAPHeaderElement;import com.cezanne.golden.user.Exception;import com.cezanne.golden.user.UserManagerServiceProxy;import javax.xml.namespace.QName;import java.net.MalformedURLException;import javax.xml.rpc.ServiceException;import javax.xml.soap.Name;import javax.xml.soap.SOAPException;public class testWebService {public static String getResult() throws ServiceException, MalformedURLException, RemoteException, SOAPException { //标识Web Service的具体路径 String endpoint = "WebService服务地址"; // 创建 Service实例 Service service = new Service(); // 通过Service实例创建Call的实例 Call call = (Call) service.createCall(); //将Web Service的服务路径加入到call实例之中. call.setTargetEndpointAddress( new java.net.URL(endpoint) );//为Call设置服务的位置 // 由于需要认证,故需要设置调用的SOAP头信息 。
Name headerName = new PrefixedQName( new QName("发布的wsdl里的targetNamespace里的url", "string_itemName") ); org.apache.axis.message.SOAPHeaderElement header = new SOAPHeaderElement(headerName); header.addTextNode( "blablabla" ); call.addHeader(header);// SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("发布的wsdl里的targetNamespace里的url", "SoapHeader"); // soapHeaderElement.setNamespaceURI("发布的wsdl里的targetNamespace里的url"); // try // { // soapHeaderElement.addChildElement("string_itemName").setValue("blablabla"); // } // catch (SOAPException e) // { // e.printStackTrace(); // } // call.addHeader(soapHeaderElement); //调用Web Service的方法 org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param; oper = new org.apache.axis.description.OperationDesc(); oper.setName("opName"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "arg0"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("mons-discovery-0.2.jar