50 messaggi dal 16 novembre 2009
Buongiorno, ho implementato un WebService in VS2012 usanto .NET 4.5. Risolti i problemi di autenticazione (Basic) si presenta il problema che la risposta invece di essere in formato testo, è Multipart, come da errore che allego. Segue anche il codice vb e il file app.config. Vi ringrazio dell'aiuto che vorrete darmi.
Saverio

Aggiornamento: leggendo una nota Microsoft sull'uso di Mtom, ho modificato il file app.config e in particolare il binding, senza nessun miglioramento:
<bindings>
<wsHttpBinding>
<binding name="svcWsHttpBinding" messageEncoding="Mtom" />
</wsHttpBinding>
</bindings>
questo è solo la parte modificata, come anche potete leggere in app.config qui sotto:

---------------------------------------errore-----------------------------------------------------------------------
Il contenuto della risposta rilevato dal client è di tipo 'multipart/related; boundary="MIMEBoundaryurn_uuid_E39B3B6C2A52BD11C21604099267201"; type="application/xop+xml"; start="<0.urn:uuid:E39B3B6C2A52BD11C21604099267202@apache.org>"; start-info="text/xml"', invece del previsto 'text/xml'.
Richiesta non riuscita con messaggio di errore:
--
--MIMEBoundaryurn_uuid_E39B3B6C2A52BD11C21604099267201
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:E39B3B6C2A52BD11C21604099267202@apache.org>

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns2:getlogResponse xmlns:ns2="http://webservices.ftp.telematico.dogana.dogane.ag_dogane.finanze.it"><getlogReturn><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:E39B3B6C2A52BD11C21604099267203@apache.org"/></getlogReturn></ns2:getlogResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_E39B3B6C2A52BD11C21604099267201
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <urn:uuid:E39B3B6C2A52BD11C21604099267203@apache.org>

---------------------------------------codice VB---------------------------------------------------------------------
Imports System.Net
Imports System.Security.Authentication

Friend Class MENU_Renamed
Inherits System.Windows.Forms.Form
Dim WithEvents wsFtp As WebRefWsFtp.TelematicoFtpWsBindingImplService
...
...

Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Const _tls12 As SslProtocols = SslProtocols.Tls12
Const Tls12 As SecurityProtocolType = CType(_tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12

Dim cert As New System.Security.Cryptography.X509Certificates.X509Certificate("D:\CERT\certificato_AUTH_00137720876-EST.cer")
wsFtp = New WebRefWsFtp.TelematicoFtpWsBindingImplService
Dim mycredentialCache As CredentialCache = New CredentialCache()
Dim credentials As NetworkCredential = New NetworkCredential("piva-postazione", "password")
mycredentialCache.Add(New Uri("https://ws-telematicoprova.adm.gov.it:443/TelematicoFtpEjbHttpRouter/TelematicoFtpWsBindingImplService"), "Basic", credentials)
wsFtp.Credentials = mycredentialCache
wsFtp.ClientCertificates.Add(cert)
wsFtp.getlogAsync()
End Sub

Private Sub wsFtp_getlogCompleted(sender As Object, e As WebRefWsFtp.getlogCompletedEventArgs) Handles wsFtp.getlogCompleted
Try
Dim res = e.Result.ToString
Dim r = res
Catch ex As Exception
Dim err As String = ex.ToString
If ex.InnerException IsNot Nothing Then err += vbCrLf + ex.InnerException.Message
End Try
End Sub
End Class


---------------------------------------------------app.config-------------------------------------------
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Banco.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="Banco.My.MySettings.BancoConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Banco.mdb"
providerName="System.Data.OleDb" />
<add name="Banco.My.MySettings.BancoConnectionString1" connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=Banco;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information"/>
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="svcWsHttpBinding" messageEncoding="Mtom" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://ws-telematicoprova.adm.gov.it:443/TelematicoFtpEjbHttpRouter/TelematicoFtpWsBindingImplService"
binding="wsHttpBinding"
bindingConfiguration="svcWsHttpBinding"
name="ChangeServiceHttpPort" />
</client>
<!--behaviorConfiguration="webEndpoint-->
<!-- contract="WebRefWsFtp.TelematicoFtpWsBindingImplService" -->
<behaviors>
<!--<endpointBehaviors>
<behavior name="webEndpoint">
<webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Xml"
helpEnabled="true"/>
</behavior>
</endpointBehaviors>-->
</behaviors>
</system.serviceModel>
<applicationSettings>
<Banco.My.MySettings>
<setting name="Banco_WebRefWsFtp_TelematicoFtpWsBindingImplService"
serializeAs="Binary">
<value>https://ws-telematicoprova.adm.gov.it:443/TelematicoFtpEjbHttpRouter/TelematicoFtpWsBindingImplService</value>
</setting>
</Banco.My.MySettings>
</applicationSettings>
</configuration>
Modificato da tesis52 il 31 ottobre 2020 10:32 -
Modificato da tesis52 il 31 ottobre 2020 10:35 -
Modificato da tesis52 il 31 ottobre 2020 10:35 -
50 messaggi dal 16 novembre 2009
Mi rispondo da solo.
Risolto il problema originale, ma ora anche se metto il certificato la call riturna un errore dicendo "http 403 - Access forbidden' e il messaggio interno "Impossibile accedere con un'autenticazione di tipo Anonymous". Ma io ho scritto che il trasporto e il messaggio devono usare un certificato, e lo fornisco pure! Boh?


Function svrCertValidate(ByVal sender As Object, ByVal certSvr As X509Certificate2, ByVal chain As X509Chain, ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
Return True
End Function

Sub CreaServizio(ByRef cert As X509Certificate2)
Dim wsBinding As New BasicHttpBinding()
wsBinding.Security.Mode = BasicHttpSecurityMode.Transport
wsBinding.MessageEncoding = WSMessageEncoding.Mtom

Const _tls12 As SslProtocols = SslProtocols.Tls12
Const Tls12 As SecurityProtocolType = CType(_tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12
ServicePointManager.ServerCertificateValidationCallback = AddressOf svrCertValidate

Dim wssAdress As New EndpointAddress("https://interop.adm.gov.it/MovimentazioniDASWeb/services/MovimentazioniDAS")

wsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate
wsBinding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.Certificate

Dim posC As Integer = CERTPROVA.LastIndexOf("\")
Dim certSrv As New X509Certificate2(CERTPROVA.Substring(0, posC + 1) + "CADoganeTest.pem")

wsSvc = New svcRefWebSvc.MovimentazioniDASClient(wsBinding, wssAdress)
wsSvc.ClientCredentials.ClientCertificate.Certificate = cert
wsSvc.ClientCredentials.ServiceCertificate.DefaultCertificate = certSrv

End Sub

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.