Category: WCF

WCF – VB.NET – Envoyer / uploader un fichier en WCF

WEB.Config :

<?xml version=”1.0″ encoding=”utf-8″?>

<!–
Pour plus d’informations sur la configuration de votre application ASP.NET, consultez
http://go.microsoft.com/fwlink/?LinkId=169433
–>

<configuration>
<system.web>
<compilation debug=”true” strict=”false” explicit=”true” targetFramework=”4.0″ />
<httpModules>
<add name=”ApplicationInsightsWebTracking” type=”Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web” />
</httpModules>
<!– ajouté–>
<httpRuntime executionTimeout=”90″ maxRequestLength=”1000000000″ />

</system.web>
<system.webServer>

<!– ajouté–>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength=”2147483648″ />
</requestFiltering>
</security>

<validation validateIntegratedModeConfiguration=”false” />
<modules>
<remove name=”ApplicationInsightsWebTracking” />
<add name=”ApplicationInsightsWebTracking” type=”Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web” preCondition=”managedHandler” />
</modules>
</system.webServer>

<runtime>

<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”System.Runtime” publicKeyToken=”b03f5f7f11d50a3a” culture=”neutral” />
<bindingRedirect oldVersion=”0.0.0.0-2.6.8.0″ newVersion=”2.6.8.0″ />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”System.Threading.Tasks” publicKeyToken=”b03f5f7f11d50a3a” culture=”neutral” />
<bindingRedirect oldVersion=”0.0.0.0-2.6.8.0″ newVersion=”2.6.8.0″ />
</dependentAssembly>
</assemblyBinding>

</runtime>

<system.serviceModel>
<!– ajouté–>
<bindings    >
<basicHttpBinding  >
<binding   transferMode=”Streamed”  maxReceivedMessageSize=”2147483647″ maxBufferSize=”2147483647″ maxBufferPoolSize=”2147483647″>
<readerQuotas maxDepth=”64″ maxArrayLength=”2147483647″ maxStringContentLength=”2147483647″/>
</binding>
</basicHttpBinding>
</bindings>

<behaviors>
<serviceBehaviors   >
<behavior name=””   >
<serviceMetadata httpGetEnabled=”true”       />
<serviceDebug includeExceptionDetailInFaults=”false”       />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled=”true”      />
</system.serviceModel>
</configuration>

 

Interface du wcf :
<OperationContract()>
Sub setExe(ByVal fichierStream As Stream)

Source .VB du wcf : 

Public Sub setExe(fichier As Stream) Implements ISvcCyrus.setExe
Dim fileStream = New FileStream(“\\data\CyrusApplication\developpement\maj\Cyrus2.exe”, FileMode.Create, FileAccess.Write)
fichier.CopyTo(fileStream)
fileStream.Dispose()
End Sub

Client  pour envoyer le fichier :

Dim service As New ServiceReference1.MonServiceClient
service.Endpoint.Address = New ServiceModel.EndpointAddress(“http://x.x.x.x/monService.svc&#8221;)

Dim stream As FileStream = File.OpenRead(cheminFichier)
service.setExe(stream)