如何在Android中的kSOAP信封中设置正确的安全标头

时间:2012-11-09 13:39:22

标签: android netbeans https glassfish ksoap2

我正在开发一个Android应用程序,它调用在GlassFish 3.1服务器上运行的SOAP Web服务。我使用NetBeans 7开发了Web服务。 在我的应用程序中,我使用kSOAP2库连接到服务器。

使用SSL保护连接,并且在证书出现问题后,可以建立连接,所以现在我必须设置我的SOAP信封的正确安全头,否则我得到一个WssSoapFaultException:无效的安全头例外服务器。问题是,我不知道安全头应该是什么样子。

我从这篇文章中了解了如何设置标题how to set soap Header using ksoap2

我试图从GlassFish管理工具中获取有关标题应如何显示的信息,但找不到任何内容。

那么我可以在Web服务文件中找到该信息,还是可以直接从生成的WSDL文件中获取该信息?

这就是我的WDSL文件的样子。

编辑: 我意识到在NetBeans中的Web服务属性(右键单击ws - >编辑Web服务属性)下,我选择了相互证书安全性。不知道是怎么回事,我确信在创建Web服务时我检查了传输安全(SSL)。无论如何,我把它放回Transport Security,现在WSDL文件要轻得多。但是仍然需要安全标题,所以我遇到了和以前一样的问题。

 <!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2.0-1 (tags/2.2.0u1-7139; 2012-06-02T10:55:19+0000) JAXWS-RI/2.2.6-2 JAXWS/2.2 svn-revision#unknown. 
-->
<!--
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2.0-1 (tags/2.2.0u1-7139; 2012-06-02T10:55:19+0000) JAXWS-RI/2.2.6-2 JAXWS/2.2 svn-revision#unknown. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://stawebservice.staws.stapf.de/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://stawebservice.staws.stapf.de/" name="stawebservice">
<wsp:Policy xmlns:wsapw3c="http://www.w3.org/2006/05/addressing/wsdl" wsu:Id="stawebservicePortBinding_Wsaw_Addressing_Policy-stawebservicePortBinding_WSAM_Addressing_Policy-stawebservicePortBinding_WSAM_Addressing_Policy">
<wsapw3c:UsingAddressing wsp:Optional="true"/>
<wsam:Addressing wsp:Optional="true">
<wsp:Policy/>
</wsam:Addressing>
</wsp:Policy>
<wsp:Policy xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" wsu:Id="stawebservicePortBindingPolicy">
<sp:TransportBinding>
<wsp:Policy>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic128/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:IncludeTimestamp/>
<sp:Layout>
<wsp:Policy>
<sp:Lax/>
</wsp:Policy>
</sp:Layout>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
</wsp:Policy>
</sp:TransportBinding>
<sp:Wss10/>
<wsam:Addressing/>
</wsp:Policy>
<types>
<xsd:schema>
<xsd:import namespace="http://stawebservice.staws.stapf.de/" schemaLocation="https://192.168.1.214:8181/STAwebservice_ssl/stawebservice?xsd=1"/>
</xsd:schema>
</types>
<message name="getPublicKey">
<part name="parameters" element="tns:getPublicKey"/>
</message>
<message name="getPublicKeyResponse">
<part name="parameters" element="tns:getPublicKeyResponse"/>
</message>
<message name="login">
<part name="parameters" element="tns:login"/>
</message>
<message name="loginResponse">
<part name="parameters" element="tns:loginResponse"/>
</message>
<message name="getOTP_HTTPS">
<part name="parameters" element="tns:getOTP_HTTPS"/>
</message>
<message name="getOTP_HTTPSResponse">
<part name="parameters" element="tns:getOTP_HTTPSResponse"/>
</message>
<message name="getOTP_SMS">
<part name="parameters" element="tns:getOTP_SMS"/>
</message>
<message name="getOTP_SMSResponse">
<part name="parameters" element="tns:getOTP_SMSResponse"/>
</message>
<message name="confirmOTP">
<part name="parameters" element="tns:confirmOTP"/>
</message>
<message name="confirmOTPResponse">
<part name="parameters" element="tns:confirmOTPResponse"/>
</message>
<portType name="stawebservice">
<operation name="getPublicKey">
<input wsaw:Action="http://stawebservice.staws.stapf.de/stawebservice/getPublicKeyRequest" wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/getPublicKeyRequest" message="tns:getPublicKey"/>
<output wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/getPublicKeyResponse" message="tns:getPublicKeyResponse"/>
</operation>
<operation name="login">
<input wsaw:Action="http://stawebservice.staws.stapf.de/stawebservice/loginRequest" wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/loginRequest" message="tns:login"/>
<output wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/loginResponse" message="tns:loginResponse"/>
</operation>
<operation name="getOTP_HTTPS">
<input wsaw:Action="http://stawebservice.staws.stapf.de/stawebservice/getOTP_HTTPSRequest" wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/getOTP_HTTPSRequest" message="tns:getOTP_HTTPS"/>
<output wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/getOTP_HTTPSResponse" message="tns:getOTP_HTTPSResponse"/>
</operation>
<operation name="getOTP_SMS">
<input wsaw:Action="http://stawebservice.staws.stapf.de/stawebservice/getOTP_SMSRequest" wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/getOTP_SMSRequest" message="tns:getOTP_SMS"/>
<output wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/getOTP_SMSResponse" message="tns:getOTP_SMSResponse"/>
</operation>
<operation name="confirmOTP">
<input wsaw:Action="http://stawebservice.staws.stapf.de/stawebservice/confirmOTPRequest" wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/confirmOTPRequest" message="tns:confirmOTP"/>
<output wsam:Action="http://stawebservice.staws.stapf.de/stawebservice/confirmOTPResponse" message="tns:confirmOTPResponse"/>
</operation>
</portType>
<binding name="stawebservicePortBinding" type="tns:stawebservice">
<wsaw:UsingAddressing/>
<wsp:PolicyReference URI="#stawebservicePortBinding_Wsaw_Addressing_Policy-stawebservicePortBinding_WSAM_Addressing_Policy-stawebservicePortBinding_WSAM_Addressing_Policy"/>
<wsp:PolicyReference URI="#stawebservicePortBindingPolicy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getPublicKey">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="login">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getOTP_HTTPS">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getOTP_SMS">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="confirmOTP">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="stawebservice">
<port name="stawebservicePort" binding="tns:stawebservicePortBinding">
<soap:address location="https://192.168.1.214:8181/STAwebservice_ssl/stawebservice"/>
</port>
</service>
</definitions>

0 个答案:

没有答案