public interface
WSIFPort { public boolean executeRequestResponseOperation (String
op,
WSIFMessage
input,
WSIFMessage
output,
WSIFMessage fault) throws
WSIFException; // some other methods not specified
here }
public
class MyWSIFPortFactory extends WSIFDynamicPortFactory { public WSIFPort
getPort () throws WSIFException { WSIFException ex = null; WSIFPort
portInstance = null; // examine list of available ports // do we have a
port with a Java binding? for(int i = 0; i < myPortsArr.length; ++i)
{ try { Port port = myPortsArr[i]; Binding binding =
port.getBinding(); if (binding instanceof JavaBinding) { // attempt to
create a port that can // make invocations using this binding portInstance
= createDynamicWSIFPort(def, service, port); if(portInstance != null)
{ return portInstance; } } } catch(WSIFException wex) { if(ex ==
null) { ex = wex; } } } // unable to create a port that can
invoke a Java // binding (why? perhaps there is no Java port // for this
service, or the Java port cannot be // created for invocation since we are
not in // an environment that has access to the resources // that the Java
binding uses) // use WSDL ports with other // bindings for invoking the
service // Full code not shown here due to length. // Please see the
Resources section at the end of // this article to download the actual code.
} }
// some methods and
other details omitted public abstract class WSIFStub { /** * Locates a
port factory using JNDI if available, * otherwise uses dynamic port factory
with * pre-registered dynamic providers */ protected void
locatePortFactory(.....) { ..... } /** * Initializes stub with ports
defined in WSDL document * document must contain *exactly* one service and
all * ports must implement one and only one port type. */ protected
void initializeFromLocation (...) { ..... } /** * Return the port
currently being used. */ public WSIFPort getPort () { return
wp; } /** * Return the port factory currently being
used. */ public WSIFPortFactory getPortFactory () { return
wpf; } /** * Create a new proxy using the given
WSIFPortFactory. */ public void setPortFactory (WSIFPortFactory wpf)
{ ..... } /** * Create a new proxy pre-configured to use the given
port * for interacting with the service. */ public void setPort
(WSIFPort wp) { ..... } /** * Select the port to use by giving the
name of the port * that is desired. If a port of that name cannot be retrived
from * the port factory than an exception will be thrown. The port * I use
will only be updated if this method is successful. */ public void
selectPort (String portName) { ..... } }
随着 Web 服务持续发展,使用 SOAP
之外的协议访问服务端点将变得很普遍。因此当我们编写使用 Web 服务的应用程序时,我们需要工作在 WSDL 级而不是在 SOAP 级的
API。
WSIF 提供了着眼于 Web 服务调用的抽象方式,这样我们可以使用不受绑定束缚的调用 API 编写应用程序。WSIF
有生成可定制存根的端口类型编译器;WSIF API 足够简单,以至于应用程序能够通过直接使用它来进行无存根调用。WSIF
的体系结构能够以灵活的方式定义定制端口和端口工厂,并且也使被创建的消息能够使用任何本机类型系统。在存根用来进行调用的端口或端口工厂中,对于受管环境(比如应用程序服务器),生成的存根有入口点来进行运行时修改。
Aleksander Slominski 是 Indiana
University 的博士生,他是 IU Extreme! Lab 的研究助理,致力于实现“公共组件体系结构”的 XML/SOAP
启用版。他还设计和实现了“XML 拖解析器”(XML Pull Parser),并且对 XML 的性能和可用性方面感兴趣。在 2001
年夏天期间,他是 IBM 的 T J Watson Research Lab 的实习生,在那里他从事 WSIF 第一版的研究。您能够通过
aslom@indiana.edu 和 Alek
联系。