Some Note for Web Service.

王朝java/jsp·作者佚名  2006-01-10
宽屏版  字体: |||超大  

WS is really a magic tech. Although i have heard something about it before, i still was excited when i tought it.

Here is some key point for me, may be also for you. If you want to got more full information, you can find some book or find other tutiols. Here we go.

I want to talk about the server side first.

1 Server side

i first try to use java to build a web service, there are so many choise, http://ws.apache.org . I first choise SOAP, as i think it is more basic, however, i just found it a little complex and i could not find more documents about it. Then i try another famous product---axis. It's really easy. After the installion and user's guide on the site, i can basicly deploy some simple web services. links: http://ws.apache.org/axis/

Here are some key notes:

The installation is easy. First put the webapps/axis to any container, like tomcat. Then, You can validate the required package in the browser. Add all the requied package to the lib in WEB-INF.Axis use a .wsdd help you to deploy, it is useless in other environment. Instead, you needn't to write any .wsdl, but you can view it after deploy. Just Add "?wsdl" after the url of your webservice.

The deploy command with .wsdd is "java org.apache.axis.client.AdminClient deploy.wsdd" (you can change the filename of .wsdd)In the .wsdd, you can define you own type and make a mapping, like

<typeMapping qname="ns:local" xmlns:ns="someNamespace"

languageSpecificType="java:my.java.thingy"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>The ArrayList or Object[] also can be add to the mapping, like

<arrayMapping qname="ns:ArrayOfthingy" xmlns:ns="someNamespaceURI"

languageSpecificType="java:my.java.array.thingy[]"

innerType="ns2:thingy" xmlns:ns2="anotherNamespaceURI"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> After you writing the file and prepare the class to deploy, you could run the command above, when you see "Process Done" in command line, the server have been deployed. you can confirm it by view the wsdl in browser.

The C# is quite easy with vs.net. Just new a web service project and run it. The most simple one is OK.

Then the the client, often more complex

2 Client side

In client you can choose either the ligh level way or low level way (parse SOAP by you self),

i just want to talk about the high level way here. The other is so complex for me now

1) With java. There are at lease three ways:

you can use you defined class to send or receive the SOAP, if you will give the class to client . Realization with axis is very easy, you can find example in its samplesIf you haven't the original class but the wsdl, that's ok. You can use wscompile command to generate the all classes used in .wsdl for you. you can type wscompile -help to got more informationAnother way is use WSDL2JAVA, but i haven't try it. It is generate something like stub and skeleton. But it is said very simple. 2) With other languages

As a cross-language tech, the SOAP must can be read by other language. The main question is how can the customized type be understand. Of course, you can read a schema in wsdl, can parse the SOAP by you self, but there must be some easy way.

i just do something with c#, the vs.net is so powerful that make the process very easy. If you have got the WSDL or know the url of it, you can new a web service project, then add a web reference, type the url of wsdl, click ok and you will find every requied class in the method of web service, with has been write in C#. How great it is. Then you can use the class to invoke the method. Meanwhile,you will find a fold and some files in you project folder.

What about other language. There are may be the same way, but i haven't try it. The most great thing is even asp or javascript can use webservices. In worst way, i think i can use the lowest level way to operate the SOAP message.I am still trying.

Anyway, avoid using complex type is more easy to be used with other language

Other notes

You can use tcptrace or MS SOAP Toolkit to check the SOAP message. It is interesting because you can view call the http message through you server.

When you configure the tool, you 'd better know how it works. I reasearch it alot then sucessfully configure it.

There are three blank: client port, server name, server port.

You should change you code as:

When you client all web service, make the port to the "client port" value you have set, it could be any number.

Set the "server port." to the reail web service port. The server name is normal, even can be localhost.

Thus the message will go from cliect to the tool then to the sever. The return path is reversed.You can have some test with www.google.com/apis.

So many things i have learned today.

Good night.

If i get more,i will share them at once

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有