package com.konnect.soap;public class helloservice{ public string hello(string name) { return "hello "+name+" pleased to meet you"; }}that's it, now all you have to do it compile the class, and place it in a location that apache soap can load it from, and then deploy it using the apache soap admin tool. in this example i have given the service an id of "urn:helloservice".
namespace helloservice{ using system.diagnostics; using system.xml.serialization; using system; using system.web.services; using system.web.services.protocols; [system.web.services.webservicebindingattribute(name="urn:itemmanager",namespace="http://localhost:8070/apache-soap/servlet/rpcrouter")] public class helloproxy: system.web.services.protocols.soaphttpclientprotocol { public helloproxy() { //you will need to adjust this url to reflect the location of your service. this.url = "http://localhost:8080/apache-soap/servlet/rpcrouter"; } /* the following attribute tells the soap client how to * encode the data it sends to the url as well as which * service on the server the request is for. * * don't worry all is explain later in the article */ [system.web.services.protocols.soapdocumentmethodattribute("",requestnamespace="urn:helloservice",responsenamespace="urn:helloservice",use=system.web.services.description.soapbindinguse.encoded, parameterstyle=system.web.services.protocols.soapparameterstyle.wrapped)] public string hello(string name) { /* call the invoke method with the method * name, and its arguments as an array of objects. */ object [] results = this.invoke("hello",new object[] { name }); /* we know that the result is a string, so we can * safely cast it to the correct type * we also know we are only expecting a singe object * to be returned so only return the 1st element */ return ((string)(results[0])); } }}//end of helloservice namespacelooks pretty simple doesn't it. the only thing that really needs to be explained are the sections of the code in '[' brackets. basically these are attributes associated with the method/class that provide extra information about the method/class.
namespace helloservice{ public class helloclient { public static void main(string [] args) { helloservice service = new helloservice(); console.writeline(service.hello("robert")); } }}//end of the helloservice namespaceall we have to do now is compile the above class. this is done using the command:
新闻热点
疑难解答