net java整合,开发能够互操作的Web Services – 整合Java and Microsoft .NET-.NET教程,Web Service开发...

encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />

encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />

code examples

now well show a few web services interoperability examples. we will use a simple banking application that is capable of keeping track of customers, accounts, and account balances. we will also use the ms .net weather service that is listed on the xmethods site as a real-life example of internet web service access, so youll need to be connected to the internet while running this demo.

note: if you havent already downloaded the software used to create the tutorial examples, please refer to the installation chapter in part one. youll also need to download the demo sources. we assume that youve unpacked this archive into the c:\wasp_demo directory. all java sources mentioned in the tutorial examples can be found in the src subdirectory of the unpacked demo sources archive. they all reside in the com.systinet.demos package. similarly all scripts used in the demo are located in the bin subdirectory. you dont need to download and use the software to understand these articles, but we strongly recommend it.

accessing a microsoft .net service from java

well start with the java client/.net service example. as we mentioned earlier, we will access the weather service listed on the xmethods site. click on the link and try the service online using the ms .net invocation framework. next look at the wsdl document for this service. youll notice that it defines three bindings (weatherretrieversoap, weatherretrieverhttpget, and weatherretrieverhttppost).

now lets create a java client for this service. run the run_weather_client.bat script thats located in the bin directory of the demo sources archive. please note that were using a lookup method that specifices the fully qualified service name and the wsdl port. this lookup method allows us to specify that we want to use the soap binding.

lookup("http://www.vbws.com/services/weatherretriever.asmx?wsdl",

new javax.wsdl.qname("http://tempuri.org/",

"weatherretriever"), "weatherretrieversoap", weatherretrieversoap.class)

calling a java service from a microsoft .net client

the opposite scenario is pretty straightforward. first start the web service runtime with the startserver.bat command, and then compile and deploy our simple bank web service by invoking the deploy.bat command. now were ready to show three different ms soap clients accessing our service.

note: you need to use ms ie 6.0 or higher to run this demo.

first we will run a ms javascript soap client. invoke the run_web_client.bat script. specify an ssn number (you can use 001-0001-01, 002-0002-02 or 003-0003-03), and click the get accounts button, which populates the accounts combobox. choose an account in the combobox and retrieve the account balance by clicking the get balance button. look at the javascript code in src\msjsclient.html for further details. the code is very self-explanatory.

note: youll need to download and install the ms soap toolkit 2.0 in order to successfully complete the next example. youll also need ms excel on your machine.

now lets see the same functionality accessed from microsoft excel (using visual basic). open the src\bank.xls spreadsheet and use the same steps described in the previous example to navigate the application. you can find the soap client code in the visual basic editor (tools->macro->visual basic editor) in the sheet1 module.

note: youll need to download and install the ms .net framework sdk to run the c# part of this example

the last example demonstrates how to access our java web service from a c# client. run the run_csharp.bat script to generate a c# static proxy from the service wsdl and to compile and run the client application. this example is going one step further than our previous examples in that it passes a transfer structure from c# to java. the previous examples pass only simple data types. notice the simple xml schema definition of the transfer type (it includes the balance element):

the .net wsdl compiler will generate the appropriate structures in c#. see the stub in the src/ms/javaservice.cs for more details. run the java client by invoking the run_java_client.bat script, and youll notice that it does the same thing.

note: both clients share the same web service, and both clients make withdrawals from the same account. so if you run the demo multiple times, you can easily get out of funds. then youll get the transferprocessingexception that says something like insufficient funds. one nice thing youll notice is that c# is able to transparently rethrow the exception with the same message on the client side. restart the web services runtime using the startserver.bat to renew your funds.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值