由於須要用到webservice接收數據,自己項目用的就是spring boot,因此直接找到spring ws。java
官方demo https://spring.io/guides/gs/producing-web-service/,也能夠看看這個服務端、客戶端,差很少,主要就是須要編寫xsd文件,參考demo中的定義,感受本身寫也很容易,就是定義數據結構。其餘的沒看過例子,也不知道能定義什麼。web
其餘的也沒怎麼探索,就上代碼說說一些小細節吧。spring
<xs:element name="getCountryRequest"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="getCountryResponse"> <xs:complexType> <xs:sequence> <xs:element name="country" type="tns:country"/> </xs:sequence> </xs:complexType> </xs:element>
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest") @ResponsePayload public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) { GetCountryResponse response = new GetCountryResponse(); Country poland = new Country(); poland.setName("Poland-" + request.getName()); poland.setCapital("Warsaw"); poland.setCurrency(Currency.PLN); poland.setPopulation(38186860); response.setCountry(poland); return response; } @Bean(name = "countries") public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) { DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); wsdl11Definition.setPortTypeName("CountriesPort"); wsdl11Definition.setLocationUri("/ws/countries.wsdl"); wsdl11Definition.setTargetNamespace("http://yournamespace/ws"); wsdl11Definition.setSchema(countriesSchema); wsdl11Definition.setServiceName(""CountriesService"); return wsdl11Definition; }
<wsdl:message name="getCountryRequest"> <wsdl:part element="tns:getCountryRequest" name="getCountryRequest"/> </wsdl:message> <wsdl:message name="getCountryResponse"> <wsdl:part element="tns:getCountryResponse" name="getCountryResponse"/> </wsdl:message> <wsdl:portType name="CountriesPort"> <wsdl:operation name="getCountry"> <wsdl:input message="tns:getCountryRequest" name="getCountryRequest"/> <wsdl:output message="tns:getCountryResponse" name="getCountryResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CountriesPortSoap11" type="tns:CountriesPort"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getCountry"> <soap:operation soapAction=""/> <wsdl:input name="getCountryRequest"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="getCountryResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding>
上面wsdl的<wsdl:operation name="getCountry">,跟GetCountryRequest和GetCountryResponse有關係,就是getCountry,首字母小寫,去掉request。若是定義的是GetCountry和GetCountryResponse(我就遇到了),會致使只有output沒有input的定義。api
<wsdl:message name="getCountryResponse"> <wsdl:part element="tns:getCountryResponse" name="getCountryResponse"/> </wsdl:message> <wsdl:portType name="CountriesPort"> <wsdl:operation name="getCountry"> <wsdl:output message="tns:getCountryResponse" name="getCountryResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CountriesPortSoap11" type="tns:CountriesPort"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getCountry"> <soap:operation soapAction=""/> <wsdl:output name="getCountryResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding>
localPart的內容須要跟服務的請求對應上,好比我改成localPart = "getCountry",若是會提示:No endpoint mapping found for [SaajSoapMessage {http://yournamespace/ws}getCountryRequest]。xcode
binding 加上soapAction:數據結構
Properties prop = new Properties(); prop.setProperty("getCountry", "http://sap.com/xi/WebService/soap1.1"); wsdl11Definition.setSoapActions(prop);
<wsdl:binding name="CountriesPortSoap11" type="tns:CountriesPort"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getCountry"> <soap:operation soapAction="http://sap.com/xi/WebService/soap1.1"/> <wsdl:input name="getCountryRequest"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="getCountryResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding>
p.s.補充,項目折騰了axis2,有個大小寫問題,按照某規範必需要大寫,axis2調用的BeanInfo方法,底層會判斷,第一個第二個字母不是連續大寫的,會把第一個字母改成小寫,折騰大半天,跟蹤代碼,實在是嵌套太多層不知怎麼入手,最後改用cxf解決了問題,參考這篇。app
完。ide