如何从ssl证书和签名属性调用Soap web服务
本文关键字:调用 属性 Soap web 服务 ssl 证书 | 更新日期: 2023-09-27 18:00:42
我必须从本地WSDL调用web服务。
所以我用Visual Studio创建了一个新项目,然后导入WSDL。
现在,要调用此web服务,我必须通过SSL证书进行连接。之后我必须签署一些属性。
因此,我已经下载了ssl证书,并且有了用于对属性进行签名的文件"keystore_healthnetbr.pfx"。
这是wsdl:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.1 (branches/2.1-6728; 2011-02-03T14:14:58+0000) JAXWS-RI/2.2.3 JAXWS/2.2. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.1 (branches/2.1-6728; 2011-02-03T14:14:58+0000) JAXWS-RI/2.2.3 JAXWS/2.2. -->
-<definitions name="PianoAssistenzialeResidenzialeService" targetNamespace="http://www.nsisr.puglia.it/Schemas/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.nsisr.puglia.it/Schemas/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
-<wsp1_2:Policy wsu:Id="NsisrPortBindingPolicy" xmlns:sunwsp="http://java.sun.com/xml/ns/wsit/policy" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:ssp="http://schemas.sun.com/2006/03/wss/server" xmlns:wsapw3c="http://www.w3.org/2006/05/addressing/wsdl">
-<sp:AsymmetricBinding>
-<wsp1_2:Policy>
-<sp:AlgorithmSuite>
-<wsp1_2:Policy>
<sp:Basic128/>
</wsp1_2:Policy>
</sp:AlgorithmSuite>
<sp:IncludeTimestamp/>
-<sp:InitiatorToken>
-<wsp1_2:Policy>
-<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
-<wsp1_2:Policy>
<sp:WssX509V3Token10/>
</wsp1_2:Policy>
</sp:X509Token>
</wsp1_2:Policy>
</sp:InitiatorToken>
-<sp:Layout>
-<wsp1_2:Policy>
<sp:Lax/>
</wsp1_2:Policy>
</sp:Layout>
-<sp:RecipientToken>
-<wsp1_2:Policy>
-<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
-<wsp1_2:Policy>
<sp:WssX509V3Token10/>
</wsp1_2:Policy>
</sp:X509Token>
</wsp1_2:Policy>
</sp:RecipientToken>
</wsp1_2:Policy>
</sp:AsymmetricBinding>
-<sp:SignedParts>
<sp:Body/>
<sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="attributiAutorizzativi" Namespace="http://www.nsisr.puglia.it/Schemas/"/>
<sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
</sp:SignedParts>
-<sp:Wss10>
-<wsp1_2:Policy>
<sp:MustSupportRefIssuerSerial/>
<sp:MustSupportRefKeyIdentifier/>
</wsp1_2:Policy>
</sp:Wss10>
<wsapw3c:UsingAddressing/>
</wsp1_2:Policy>
-<types>
-<xsd:schema>
<xsd:import schemaLocation="PianoAssistenzialeResidenzialeService.xsd" namespace="http://www.nsisr.puglia.it/Schemas/"/>
</xsd:schema>
</types>
-<message name="getPianoAssistenziale">
<part name="parameters" element="tns:getPianoAssistenziale"/>
<part name="attributiAutorizzativi" element="tns:attributiAutorizzativi"/>
</message>
-<message name="getPianoAssistenzialeResponse">
<part name="result" element="tns:getPianoAssistenzialeResponse"/>
</message>
-<message name="setRichiestaProroga">
<part name="parameters" element="tns:setRichiestaProroga"/>
<part name="attributiAutorizzativi" element="tns:attributiAutorizzativi"/>
</message>
-<message name="setRichiestaProrogaResponse">
<part name="result" element="tns:setRichiestaProrogaResponse"/>
</message>
-<message name="getPianoAssistenzialeDomiciliare">
<part name="parameters" element="tns:getPianoAssistenzialeDomiciliare"/>
<part name="attributiAutorizzativi" element="tns:attributiAutorizzativi"/>
</message>
-<message name="getPianoAssistenzialeDomiciliareResponse">
<part name="result" element="tns:getPianoAssistenzialeDomiciliareResponse"/>
</message>
-<message name="getElencoPAI">
<part name="parameters" element="tns:getElencoPAI"/>
<part name="attributiAutorizzativi" element="tns:attributiAutorizzativi"/>
</message>
-<message name="getElencoPAIResponse">
<part name="result" element="tns:getElencoPAIResponse"/>
</message>
-<message name="setOspitalitaRSA">
<part name="parameters" element="tns:setOspitalitaRSA"/>
<part name="attributiAutorizzativi" element="tns:attributiAutorizzativi"/>
</message>
-<message name="setOspitalitaRSAResponse">
<part name="result" element="tns:setOspitalitaRSAResponse"/>
</message>
-<message name="getElencoPAIDomiciliare">
<part name="parameters" element="tns:getElencoPAIDomiciliare"/>
<part name="attributiAutorizzativi" element="tns:attributiAutorizzativi"/>
</message>
-<message name="getElencoPAIDomiciliareResponse">
<part name="result" element="tns:getElencoPAIDomiciliareResponse"/>
</message>
-<portType name="PianoAssistenzialeResidenziale">
-<operation name="getPianoAssistenziale" parameterOrder="parameters attributiAutorizzativi">
<input message="tns:getPianoAssistenziale" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getPianoAssistenzialeRequest"/>
<output message="tns:getPianoAssistenzialeResponse" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getPianoAssistenzialeResponse"/>
</operation>
-<operation name="setRichiestaProroga" parameterOrder="parameters attributiAutorizzativi">
<input message="tns:setRichiestaProroga" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/setRichiestaProrogaRequest"/>
<output message="tns:setRichiestaProrogaResponse" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/setRichiestaProrogaResponse"/>
</operation>
-<operation name="getPianoAssistenzialeDomiciliare" parameterOrder="parameters attributiAutorizzativi">
<input message="tns:getPianoAssistenzialeDomiciliare" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getPianoAssistenzialeDomiciliareRequest"/>
<output message="tns:getPianoAssistenzialeDomiciliareResponse" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getPianoAssistenzialeDomiciliareResponse"/>
</operation>
-<operation name="getElencoPAI" parameterOrder="parameters attributiAutorizzativi">
<input message="tns:getElencoPAI" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getElencoPAIRequest"/>
<output message="tns:getElencoPAIResponse" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getElencoPAIResponse"/>
</operation>
-<operation name="setOspitalitaRSA" parameterOrder="parameters attributiAutorizzativi">
<input message="tns:setOspitalitaRSA" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/setOspitalitaRSARequest"/>
<output message="tns:setOspitalitaRSAResponse" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/setOspitalitaRSAResponse"/>
</operation>
-<operation name="getElencoPAIDomiciliare" parameterOrder="parameters attributiAutorizzativi">
<input message="tns:getElencoPAIDomiciliare" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getElencoPAIDomiciliareRequest"/>
<output message="tns:getElencoPAIDomiciliareResponse" wsam:Action="http://www.nsisr.puglia.it/Schemas/PianoAssistenzialeResidenziale/getElencoPAIDomiciliareResponse"/>
</operation>
</portType>
-<binding name="PianoAssistenzialeResidenzialePortBinding" type="tns:PianoAssistenzialeResidenziale">
<wsp1_2:PolicyReference URI="#NsisrPortBindingPolicy"/>
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
-<operation name="getPianoAssistenziale">
<soap:operation soapAction=""/>
-<input>
<soap:body parts="parameters" use="literal"/>
<soap:header message="tns:getPianoAssistenziale" use="literal" part="attributiAutorizzativi"/>
</input>
-<output>
<soap:body use="literal"/>
</output>
</operation>
-<operation name="setRichiestaProroga">
<soap:operation soapAction=""/>
-<input>
<soap:body parts="parameters" use="literal"/>
<soap:header message="tns:setRichiestaProroga" use="literal" part="attributiAutorizzativi"/>
</input>
-<output>
<soap:body use="literal"/>
</output>
</operation>
-<operation name="getPianoAssistenzialeDomiciliare">
<soap:operation soapAction=""/>
-<input>
<soap:body parts="parameters" use="literal"/>
<soap:header message="tns:getPianoAssistenzialeDomiciliare" use="literal" part="attributiAutorizzativi"/>
</input>
-<output>
<soap:body use="literal"/>
</output>
</operation>
-<operation name="getElencoPAI">
<soap:operation soapAction=""/>
-<input>
<soap:body parts="parameters" use="literal"/>
<soap:header message="tns:getElencoPAI" use="literal" part="attributiAutorizzativi"/>
</input>
-<output>
<soap:body use="literal"/>
</output>
</operation>
-<operation name="setOspitalitaRSA">
<soap:operation soapAction=""/>
-<input>
<soap:body parts="parameters" use="literal"/>
<soap:header message="tns:setOspitalitaRSA" use="literal" part="attributiAutorizzativi"/>
</input>
-<output>
<soap:body use="literal"/>
</output>
</operation>
-<operation name="getElencoPAIDomiciliare">
<soap:operation soapAction=""/>
-<input>
<soap:body parts="parameters" use="literal"/>
<soap:header message="tns:getElencoPAIDomiciliare" use="literal" part="attributiAutorizzativi"/>
</input>
-<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
-<service name="PianoAssistenzialeResidenzialeService">
-<port name="PianoAssistenzialeResidenzialePort" binding="tns:PianoAssistenzialeResidenzialePortBinding">
<soap:address location="https://edottotest.sanita.regione.rsr.rupar.puglia.it/nsisr/PianoAssistenzialeResidenzialeService"/>
</port>
</service>
</definitions>
所以我构建了这个代码:
string pathCertificato = @"C:'Users'michele.castriotta'Desktop'Certificati'keystore_healthnetbr.pfx";
X509Certificate2 certificatoLocale = new X509Certificate2(File.ReadAllBytes(pathCertificato), "changeit");
PianoAssistenzialeResidenzialeClient ws_Client = new PianoAssistenzialeResidenzialeClient();
ws_Client.ClientCredentials.ClientCertificate.Certificate=certificatoLocale;
ws_Client.ClientCredentials.ServiceCertificate.DefaultCertificate = certificatoLocale;
EndpointAddress addressClient = ws_Client.Endpoint.Address;
ws_Client.Endpoint.IsSystemEndpoint = true;
ws_Client.ClientCredentials.UserName.UserName = "HN";
ws_Client.ClientCredentials.UserName.Password = "changeit";
PianoAssistenzialeResidenzialeService.attributiAutorizzativi attributi = new PianoAssistenzialeResidenzialeService.attributiAutorizzativi();
attributi.identificativoServizio="getElencoPAIDomiciliare";
attributi.identificativoUtente="HN";
attributi.ruoloIstituzionale="RIS02";
ws_Client.getElencoPAIDomiciliare(attributi, new PianoAssistenzialeResidenzialeService.getElencoPAIDomiciliare());
如果我试图运行它,我会出现以下错误:
无法在输出中完成MESSAGE的标识控制。远程DNS的标识应为"edottotest.sania.regione.rsr.rupar.puglia.it",但"远程终结点"具有证书提供的DNS"HEALTHNETBR"。如果它是合法的远程端点,您可以通过显式指定"identity DNS"HEALTHNETBR"come properties identity EndpointAddress During the delegate of the channel "来解决问题
我已经用以下代码修复了我的错误:
EndpointIdentity identity = EndpointIdentity.CreateDnsIdentity("HEALTHNETBR");
EndpointAddress address = new EndpointAddress(new Uri("https://edottotest.sanita.regione.rsr.rupar.puglia.it/nsisr/PianoAssistenzialeResidenzialeService"), identity);
ws_Client.Endpoint.Address = address;