cxf spring发布webservice供.net使用


cxfはxfireの代替ツールです。webserviceをリリースします。公式サイト:http://cxf.apache.org/使用については、下記の通り参照できます。
公式:http://cxf.apache.org/docs/writing-a-service-with-spring.html
 
または:CXFを使ってwebserviceのリリース+springを実現します。
 
または:XFireの次世代製品CXFの入門(二)-Springとの集積
 
文章には多くの注釈が使われていますが、実は二つか一つで十分です。
注意すべき点は以下の点です。
1.jarバッグを導入する必要があります。cxf-23.11.jar neethi-2.04.jar wsdl 4 j-1.6.22.jar Xml Schema-1.4.jar xpp 3_min-1.1.4 c.jar
他にも来るかもしれませんが、状況によっては自分で導入します。
 
2.インターフェースと実現、および方法を書いたら、@WebServiceのインターフェースを一つ追加して、インターフェースと実現を下記の通りにします。
@WebService(endpointInterface = "com.phpxiaoxinl.remote.service.HotelReservationService")
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
public class HotelReservationServiceImpl implements HotelReservationService {
    @Override
    public SearchHotelRS searchHotel(SearchHotelRQ searchHotelRequest) {
        //impl
        return null;
    }
}
 ここで@BindingTypeの注釈を使って、wsdlをsop 1.2プロトコルに発表します。1.2と1.1の違いはwsdlで見られます。そのうち1.2はあります。
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
  
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
これを除いたら、その契約はデフォルトで1.1.
 
もう一つの問題があります。私はsearch HotelRQを使っています。search Hotelrequestではなく、search Hotel Reponseを使っています。search Hotel Reponseの原因は私が注釈をつけていないからです。cxfはwsdlを生成する時に名前空間が自動的にrequestまたはreponseを追加します。この方法名と入力出力は同じ名前空間になります。ですから、入力と出力をrequestまたはreponseに持たないほうがいいです。そうでなければ、search Hotelの方法名を他のものに変えたほうがいいです。
 
3.データバインディング問題。
インターネットで呼び出すと、vsは自動的にオブジェクトを生成することができますが、デフォルトではフィールド名+Specifiedのフィールドが生成されます。理由の詳細は参照してください。
http://it.chinawin.net/softwaredev/article-13328.html
この問題はその原因がよく分かりません。データ変換の問題があると思います。これはaegisによって解決できます。具体的な配置は以下の通りです。
 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="
	        http://www.springframework.org/schema/beans
	        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
	        http://cxf.apache.org/jaxws
	        http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <!--       -->
    <bean id="hotelB2CReservationService" class="com.phpxiaoxin.service.HotelReservationServiceImpl">
        <property name="bookingHotelService" ref="bookingHotelService"/>
    </bean>
    <jaxws:endpoint id="hotelReservation" implementor="#hotelReservationService"
        address="/hotelReservation">
        <jaxws:serviceFactory>
           <ref bean='jaxws-and-aegis-service-factory' />
          </jaxws:serviceFactory>
    </jaxws:endpoint>

<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype"/>
 <bean id="jaxws-and-aegis-service-factory"
    class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
    scope="prototype">
        <property name="dataBinding" ref="aegisBean"/>
 </bean>

</beans>
 
cxf公式文書も参照できます。
http://cxf.apache.org/docs/aegis-databinding-20x.html
 
このように生成されたwsdlは、
<xs:element minOccurs="0" name="branchId" type="xs:long"></xs:element>
 となります
 
<xsd:element minOccurs="0" name="branchId" nillable="true" type="xsd:long"></xsd:element>
 
切り替え後、私が直面した最初の問題は:
java.lang.Uspecification“null”version“null”
調べてみましたが、jarカバンのせいです。解析xmlのjar:xercesImpl-2.9.1.jarは2.9.1以上を使います。参考できる:
https://jira.kuali.org/browse/KULRICE-2810
 
二つ目は.net呼び出し時にエラーが発生しました。
理由は.net呼び出し時に圧縮xmlのパラメータを設定したからです。
参考:HttpTransport BindingElement.DecomppressionEnabled
以上です
 
また、私が遭遇した問題はweblogicをサーバーとして使ったため、インターネットで呼び出した時に下記のようなエラーが発生しました。
Usupported encoding:「utf-8」action="""specified.java.io.Unipported EnccodingException:Unipported Encocding utf-8;action=「」        at weblogic.servlet.internal.Servlet Request Impl.set CharcterEnccoding(ServletRequest Impl.java:428)
エラーの原因は.netでsop 1.2プロトコルを使用したためで、生成されたheaderは:
Headers:{content-type=[apple/sop+xml]charset=utf-8action=「」
 
そして、sop 1.1は以下のheaderを生成する。
Headers:{content-type=[text/xml]charset=UTF-8、SOAPAction=[]]
 
weblogic解析の時にバグが発生しました。utf-8の後の内容を切っていませんでした。このエラーが発生しました。したがって、サウンド1.1に設定して呼び出すことができます。具体的に.netの設定は文書の中でsopapを探すことができて、関連している配置を探し当てて、配置ファイルの中で設定して、下の住所をも参照することができます。
参考:http://www.coderanch.com/t/224524/Web-Services/java/SOAPAction-header
 
cxfであれば、他の人が提供するwebserviceを呼び出し、すでにwsdlがある場合は、この記事を参考にして完成することができます。
http://blogold.chinaunix.net/u2/73798/showart_200218.8.
主にcxfで提供されるツールを通じて、コマンドラインでjavaオブジェクトを生成します。
wsdl 2 java-d src-clienthttp://localhost:8080/webservice/hotelB?wsdl
 
この文章もいいです。
http://enna.blog.163.com/blog/static/2058701120093242346371/