.NET与J2EE应用互操作性实现指南
发布时间: 2025-08-17 02:37:52 阅读量: 1 订阅数: 5 


Microsoft.NET与J2EE互操作性指南
### .NET与J2EE应用互操作性实现指南
在当今的软件开发领域,实现不同技术栈之间的互操作性至关重要。本文将详细介绍如何在Java Web服务和.NET应用程序之间实现互操作性,主要涵盖Web服务配置、.NET互操作性适配器创建、JNBridgePro的使用等内容。
#### 1. Java Web服务配置
在创建好为Web服务提供功能的类后,需要告知GLUE相关信息。具体操作步骤如下:
1. 进入`XBikesBLLServiceInterface\Web Content\WEB-INF\services`文件夹,复制并重命名示例配置文件`Sample.xml`为`BLLWSServiceInterface.xml`。
2. 修改`BLLWSServiceInterface.xml`文件:
- 将`constructor`标签改为`xbikes.bll.serviceinterface.j2ee.we.BLLWSServiceInterface`。
- 将`description`标签改为`Bikes Unsecure Web Service`。
- 将`publish`标签改为`yes`,`style`改为`document`。
- 修改`interface`标签,将`electric.util.sample.ISample`替换为`xbikes.bll.serviceinterface.j2ee.ws.IBLLWSServiceInterface`,`targetNamespace`改为`http://www.xbikes.com/`。
3. 将之前创建的映射文件复制到`Web Content\WEB-INF\Maps`文件夹。
4. 测试Web服务:编译并启动服务器,打开浏览器,访问`http://localhost:9080/XBikesBLLServiceInterface/Console`,使用GLUE控制台调用`authenticateCustomer`方法。
#### 2. 创建.NET互操作性适配器
在Java中创建好Web服务接口后,就可以开始构建.NET互操作性适配器,具体步骤如下:
- **构建基于XSD架构的.NET数据类**:为了让.NET Framework应用程序能够消费Java Web服务的数据,需要创建一个可以用返回的XML字符串填充的.NET类。可以使用`XSD.EXE`工具,该工具接受`/dataset`开关来生成子类化的数据集。例如,要创建`CustomerData`数据类型,可在Visual Studio .NET 2003命令提示符中执行以下命令:
```plaintext
xsd CustomerData.xsd /dataset /namespace:xbikes.common.schemas
```
然后将生成的文件复制到`XBikes-Common`项目中。
- **构建.NET Web服务代理**:可以使用Visual Studio .NET或`wsdl.exe`命令行工具来构建Web服务的代理类。在XBikes项目中,开发人员使用Visual Studio .NET的“添加Web引用”功能创建代理,并将其添加到`XBikes-UseCaseInteropAdapters`项目中。Java WSDL的URL为`http://localhost:9080/XBikesBLLServiceInterface/services/BLLWSServiceInterface.wsdl`,开发团队将Web引用的默认名称`localhost`重命名为`J2EE.BLLWSSI`,生成的代理类属于`XBikes.UseCaseInteropAdapters.J2EE.BLLWSSI`命名空间。
- **创建.NET互操作性适配器**:可以选择为每个Web服务创建一个适配器,或者为每个用例创建一个适配器。XBikes开发人员为每个用例创建了适配器以获得最大的灵活性。以`AuthenticateCustomer`用例为例,在`XBikes-UseCaseInteropAdapters`项目的`J2EE\WS`文件夹中添加一个名为`AuthenticateCustomerInteropAdapter`的新类,并使其实现`IUseCaseCommand`接口,需要实现`Initialise`和`Execute`方法,以下是相关代码:
```csharp
public AuthenticateCustomerInteropAdapter()
{
try
{
// Instantiate the BLL service interface proxy.
// Creates a J2EE-side BLL service interface
_facade = new BLLWSServiceInterface();
}
catch (Exception e)
{
throw new XBikesInteropException("[AuthenticateCustomer]: J2EE WS Interop Adapter error: ", e);
}
}
private string _email;
private string _password;
public void Initialise(object[] parameters)
{
_email = (string) parameters[0];
_password = (string) parameters[1];
}
public DataSet Execute()
{
try
{
//Retrieve customer data as an XML Document in a string format.
StringReader sr = new StringReader(_facade.authenticateCustomer(_email,_password));
CustomerData ds = new CustomerData();
//Load result string back into CustomerData typed DataSet.
ds.ReadXml(sr);
return ds;
}
//soap error
catch (System.Web.Services.Protocols.SoapException soapExp)
{
string soapFaultMsg = soapExp.Message;
//Parse SoapException message to get exception type.
string ExceptionType = ExceptionHelper.GetSoapExceptionType(soapFaultMsg);
//Throw the appropriate exception type based on the
//exception type found in the SoapException.
switch (ExceptionType)
{
case "Interop":
throw(new XBikesInteropException(soapFaultMsg));
case "Application" :
throw(new XBikesApplicationException(soapFaultMsg));
default:
throw(new XBikesApplicationException(soapFaultMsg));
}//switch
}
//general error
catch (Exception e)
{
//Wrap in Interop Exception
XBikesInteropException intExp = new XBikesInteropException("AuthenticateCustomer WS Interop Adapter error.",e);
//Throw up the stack to client for logging.
throw (intExp);
}
}
```
#### 3. 使用JNBridgePro实现互操作性
JNBridgePro可用于在.NET Web层和J2EE业务层之间进行桥接,以下是具体步骤:
- **选择数据格式**:JNBridgePro能够为Java数据类在.NET中生成代理类,但为了便于在
0
0
相关推荐










