我需要使用wsdl文件创建soap服务器,并允许我的客户端使用带有非wsdl模式的soap客户端的webservice。
如果有人可以发布示例工作网络服务代码,我将非常感激。我遇到了非wsdl soap客户端的问题。 stackoverflow上没有人可以回答我以前的问题,所以我现在要求提供示例代码。
答案 0 :(得分:0)
lets go, This is a sample hello world soap web service program, Go through the program, if u doesn't understand anything ask me ...
actually, there are few styles available in soap binding, here i have used the rpc
package com.kowthal.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
@WebMethod String getHelloWorldAsString(String name);
}
This is for implementation panel, the returned value will be mapped in soap webservice call
package com.kowthal.ws;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "com.kowthal.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
@Override
public String getHelloWorldAsString(String name) {
return "soap done by " + name;
}
}
this is the endpoint, here i had bind the data with specific url please note down the packages
package com.kowthal.endpoint;
import javax.xml.ws.Endpoint;
import com.kowthal.ws.HelloWorldImpl;
//Endpoint publisher
public class HelloWorldPublisher{
public static void main(String[] args) {
Endpoint.publish[juz tag]("http://localhost:9988/ws/hello", new HelloWorldImpl());
}
}
This one is for client side communication
package com.kowthal.client;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.kowthal.ws.HelloWorld;
public class HelloWorldClient{
public static void main(String[] args) throws Exception {
URL url = new URL[juz tag]("http://localhost:9988/ws/hello?wsdl");
QName qname = new QName[juz tag]("http://ws.kowthal.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString("kowthal"));
}
}
after that using this url u can retrive the xml data
[juz tag]"http://localhost:9988/ws/hello?wsdl"