locked
Using a WebService .NET4.5 to Send Request & Get Responses as multipart/related (javax-ws svc hosted in Apache) RRS feed

  • Question

  • I created a WebService in VisualStudio Professional (.NET 2.0) and I migrated it to VS 2019 (.NET 4.7.2)
    I set authentication to Basic as required by the service and I can connect to the configured endpoint, which as a response to DirAsync request issues an error as shown in the following section. After this section there's the relevant vb code and app.config.
    Please note that to issue a put (the main operation) I have to insert in the request a multipart/related message as well, namely the file name and an array of byte as the conversion from an xml file, signed to become a .p7m signed file

    -------------------------errore catturato in try...end try--error catched in try...end try block----------------------

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

    <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns2:dirResponse xmlns:ns2="http://webservices.ftp.telematico.dogana.dogane.ag_dogane.finanze.it"><dirReturn></dirReturn></ns2:dirResponse></soapenv:Body></soapenv:Envelope>
    --MIMEBoundaryurn_uuid_E39B3B6C2A52BD11C21604500039235--
    --.
    =====================relevant vb code==================================

    Option Strict Off
    Option Explicit On

    Imports System.Net
    Imports System.Security.Authentication
    Imports System.Threading
    Imports System.Threading.Tasks

    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

            wsFtp = New WebRefWsFtp.TelematicoFtpWsBindingImplService
            Dim mycredentialCache As CredentialCache = New CredentialCache()
            Dim credentials As NetworkCredential = New NetworkCredential("LogId", "Password")
            mycredentialCache.Add(New Uri("https://ws-telematicoprova.adm.gov.it:443/TelematicoFtpEjbHttpRouter/TelematicoFtpWsBindingImplService"), "Basic", credentials)
            wsFtp.Credentials = mycredentialCache
            wsFtp.dirAsync("?")
        End Sub


        Private Sub wsFtp_dirCompleted(sender As Object, e As WebRefWsFtp.dirCompletedEventArgs) Handles wsFtp.dirCompleted
            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

    ++++++++++++++++++++++++++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.7.2"/>
        </startup>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="TelematicoFtpWsBindingImplSoapBinding">
                        <security mode="Transport"/>
                    </binding>
                    <binding name="TelematicoFtpWsBindingImplSoapBinding1"/>
                </basicHttpBinding>
            </bindings>
          <client>
            <endpoint address="https://ws-telematicoprova.adm.gov.it:443/TelematicoFtpEjbHttpRouter/TelematicoFtpWsBindingImplService" binding="basicHttpBinding" bindingConfiguration="TelematicoFtpWsBindingImplSoapBinding" contract="svcRefWsFtp.TelematicoFtpWsBindingImpl" name="TelematicoFtpWsBindingImpl"/>
          </client>
          <behaviors>
          </behaviors>
        </system.serviceModel>
        <applicationSettings>
            <Banco.My.MySettings>
                <setting name="Banco_WebRefWsFtp_TelematicoFtpWsBindingImplService" serializeAs="String">
                    <value>https://ws-telematicoprova.adm.gov.it:443/TelematicoFtpEjbHttpRouter/TelematicoFtpWsBindingImplService</value>
                </setting>
            </Banco.My.MySettings>
        </applicationSettings>
    </configuration>


    • Edited by SaverioTed52 Thursday, November 5, 2020 6:30 PM typos
    Thursday, November 5, 2020 6:27 PM

All replies

  • Try to set the BasicHttpBinding.MessageEncoding property to "MTOM":

    <configuration>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding messageEncoding="Mtom">          
            </binding>
          </basicHttpBinding>
        </bindings>
      </system.serviceModel>
    </configuration>

    Monday, November 9, 2020 2:59 AM