SOAP WS Generate Client Objects And WS Consuming With Apache CXF

buradaki adresten Apache CXF paketini indirip ilgili bir dizine bırakmalısınız. Dinamik Web Projesi oluşturmalısınız. Aşağıdaki gibi: Eclipse-> New-> Other-> Web-> Dynamic Web Project-> New Dynamic Web Project Window Project Name :MyNewWebProjectName Target runtime :Apache Tomcat v8.0 Dynamic web module version :3.0 Configuration :Modify-> to be clicked CXF 2.x Web Services 1.0-> Next-> Next-> to be clicked Generate web.xml deploymnet descriptor-> CXF Facet Window CXF runtime :Apache CXF 3.1.13 (Configure installed runtimes içinde indirdiğiniz CXF i hedef gösterebilirsiniz.)-> Finish Size gelen WSDL dosyasını WebContent-> wsdl-> wsclient.wsdl şeklinde dizine bırakabilirsiniz. WebContent-> wsdl-> wsclient.wsdl-> Web Service-> Generate Client-> Web Service Client window:: Service definition :/myyApp/WebContent/wsdl/wsclient.wsdl Client type :Java Proxy Client generation level: Develop Client Configuration: Web service runtime: Apache CXF 2.x-> Next-> Package Name: net.yazilimcity.applicationname.core.ws.client.report.account-> Next-> Finish Eclipse Console penceresi günlüklerinde aşağıdaki gibi başarılı çıktı ifadesini görmelisiniz. [code language=”shell”] Loading FrontEnd jaxws … Loading DataBinding jaxb … wsdl2java -client -d C:\Users\SAPRIB\btc\git\YCNeShop_core\YCNeShop_core\.cxftmp/src -classdir C:\Users\SAPRIB\btc\git\YCNeShop_core\YCNeShop_core\bin -p http://remote/address:methodname=net.yazilimcity.myapplication.core.ws.client.order.onsiterequestcreate -impl -validate -exsh false -dns true -dex true -autoNameResolution -wsdlLocation file:/C:/Users/SAPRIB/btc/git/YCNeShop_core/YCNeShop_core/WebContent/wsdl/order/onsiterequestcreate/eShopTechReqCreate_20161123_1214.wsdl -verbose -defaultValues -fe jaxws -db jaxb -wv 1.1 file:/C:/Users/SAPRIB/btc/git/YCNeShop_core/YCNeShop_core/WebContent/wsdl/order/onsiterequestcreate/eShopTechReqCreate_20161123_1214.wsdl wsdl2java – Apache CXF 3.1.3 [/code] Yukarıdaki adımlardan sonra artık gösterdiğiniz dizinde istemci sınıflarını oluştuğunu görebilirsiniz. Aşağıdaki yabancı kaynaklardan da CXF Web Service Client oluşturma konusunda yararlanabilirsiniz: Generate a JAX-WS Web Service Client from a WSDL document using Apache CXF Artık istemciniz mevcut, bundan sonrasında ise aşağıdkai gibi farklı yollar ile WS çağırımını yapabilirisiniz. Burada WS’i çağırma esnasında kullanacağınız 2 tane sınıf olacaktır bunları _Client sınıfındaki main metodunda ilk if bloğundan sonraki 2 satırdaki objeleri aşağıdaki gibi sırasıyla kod içerisinde farklı constructor lar gerekli ise değiştirerek ilerleyebilirsiniz. Yöntem 1: [code language=”java”] try { System.getProperties().put("http.proxyHost", "10.10.10.10"); System.getProperties().put("http.proxyPort", "8080"); System.getProperties().put("http.proxyUser", "YCN\\USER"); System.getProperties().put("http.proxyPassword", "PASSWORD"); String soapEndpointAddress = "http://" + "yazilimcity.net" + "/ERP/ErpWebService.svc"; URL wsdlLocation = new URL(soapEndpointAddress + "?singleWsdl"); QName serviceQName = new QName("http://yazilimcity.com/ERP", "ErpWebService"); QName BasicHttpBindingIErpWebService = new QName("http://yazilimcity.net/ERP", "BasicHttpBinding_IErpWebService"); net.yazilimcity.eshop.core.ws.client.payment.erp.ErpWebService erpServiceWsClient = new net.yazilimcity.eshop.core.ws.client.payment.erp.ErpWebService(wsdlLocation, serviceQName); net.yazilimcity.eshop.core.ws.client.payment.erp.IErpWebService service = erpServiceWsClient.getPort(BasicHttpBindingIErpWebService, net.yazilimcity.eshop.core.ws.client.payment.erp.IErpWebService.class); BindingProvider bindingProvider = (BindingProvider) service; bindingProvider.getRequestContext().put(ConstantsApp.CXF_MAX_CHILD_TEXT, ConstantsApp.CXF_MAX_CHILD_SIZE); bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, soapEndpointAddress); System.out.println(service.toString()); } catch (Exception e) { System.out.println(e.getMessage()); } } [/code] Yöntem 2: [code language=”java”] try { System.getProperties().put("http.proxyHost", "10.10.10.10"); System.getProperties().put("http.proxyPort", "8080"); System.getProperties().put("http.proxyUser", "YCN\\USER"); System.getProperties().put("http.proxyPassword", "PASSWORD"); String soapEndpointAddress = "http://net.yazilimcity" + "/ERP/ErpWebService.svc"; URL wsdlLocation = new URL(soapEndpointAddress + "?singleWsdl"); net.yazilimcity.eshop.core.ws.client.payment.erp.ErpWebService erpServiceWsClient = new net.yazilimcity.eshop.core.ws.client.payment.erp.ErpWebService(wsdlLocation); net.yazilimcity.eshop.core.ws.client.payment.erp.IErpWebService service = erpServiceWsClient.getBasicHttpBindingIErpWebService(); // http conduit configure // Client client = ClientProxy.getClient(service); // doHttpConduitConf(client, 0, 0); BindingProvider bindingProvider = (BindingProvider) service; bindingProvider.getRequestContext().put(ConstantsApp.CXF_MAX_CHILD_TEXT, ConstantsApp.CXF_MAX_CHILD_SIZE); bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, soapEndpointAddress); } catch (Exception e) { System.out.println(e.getMessage()); } } [/code] Yöntem 3: [code lang=”java”] JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(ZB2BWB2.class); factory.setAddress("http://192.168.1.1:8000/sap/bc/srt/rfc/sap/zb2b_wb2/200/zb2b_wb_srv2/zb2b_wb_srv2_bind"); ZB2BWB2 info = (ZB2BWB2) factory.create(); Client client = ClientProxy.getClient(info); HTTPConduit http = (HTTPConduit) client.getConduit(); http.getAuthorization().setUserName("btc"); http.getAuthorization().setPassword("btc123"); net.yazilimcity.TableOfBapiret2 _zb2BLogon__returnVal = new yazilimcity.TableOfBapiret2(); javax.xml.ws.Holder<net.yazilimcity.TableOfBapiret2> _zb2BLogon__return = new javax.xml.ws.Holder<net.yazilimcity.TableOfBapiret2>(_zb2BLogon__returnVal); javax.xml.ws.Holder<net.yazilimcity.Zb2BUsr> _zb2BLogon_zb2BUsr = new javax.xml.ws.Holder<net.yazilimcity.Zb2BUsr>(); info.zb2BLogon("1", "1", "1", _zb2BLogon__return, "1", _zb2BLogon_zb2BUsr); System.out.println("zb2BLogon._zb2BLogon__return=" + _zb2BLogon__return.value); System.out.println("zb2BLogon._zb2BLogon_zb2BUsr=" + _zb2BLogon__return.value.getItem().get(0).message); [/code] ZB2BWB2.class oluşturulan SOAP WS client objeleri içerisindeki interface’dir. [code lang=”java”] @WebService(targetNamespace = "urn:sap-com:document:sap:soap:functions:mc-style", name = "ZB2B_WB2") @XmlSeeAlso({ObjectFactory.class}) public interface ZB2BWB2 {} [/code] Bu yöntemleri Apache CXF veya Jvnet Maven JAXB Plugin ile oluşturduğunuz objeleri kullanabilirsiniz.]]>

Leave a Reply

Your email address will not be published. Required fields are marked *