I
I
Ivan Vyrov2016-04-07 13:09:48
C++ / C#
Ivan Vyrov, 2016-04-07 13:09:48

WCF file transfer problem, how to solve?

Good afternoon!
There is a WCF service for transferring files from the server to the client:
IOAuth.cs

[OperationContract(Name = "FileServerToClient")]
        byte[] FileServerToClient(string type);

OAuth.cs
public byte[] FileServerToClient(string type)
        {
            try
            {
                if (type == "Client")
                {
                    FileStream fs = new FileStream(@"E:\Обновление ГАС Управление\Update\GAS-ASU.exe", FileMode.Open);
                    buffer = new byte[fs.Length];
                    int len = (int)fs.Length;
                    fs.Read(buffer, 0, len);
                    fs.Close();
                }
                else
                {
                    if (type == "Config")
                    {
                        FileStream fs = new FileStream(@"E:\Обновление ГАС Управление\Update\GAS-ASU.exe.config", FileMode.Open);
                        buffer = new byte[fs.Length];
                        int len = (int)fs.Length;
                        fs.Read(buffer, 0, len);
                        fs.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                log(ex.ToString(), "Функция  Update_file");
            }
            return buffer;
        }

Server config (ip addresses changed)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="mexBehaviors" name="Сервер_авторизации.OAuth">
        <endpoint address="OAuth" binding="basicHttpBinding" contract="Сервер_авторизации.IOAuth" />
        <endpoint address="OAuth" binding="mexTcpBinding" contract="Сервер_авторизации.IOAuth" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://10.10.10.10:1020/" />
            <add baseAddress="net.tcp://10.10.10.10:1021/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviors">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="ServiceWithAuthentication.CustomUserNameValidator, ServiceWithAuthentication" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00"
          sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <security>
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

and client (excerpt from client):
var client = new svc.OAuthClient("MetadataExchangeTcpBinding_IOAuth");
client.Open();
FileStream fss = new FileStream(Application.StartupPath + @"\GAS-ASU.exe", FileMode.Create, FileAccess.Write);
fss.Write(client.FileServerToClient("Client"), 0, client.FileServerToClient("Client").Length);
fss.Close();

Client config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IOAuth" closeTimeout="00:05:00" openTimeout="00:05:00" maxBufferPoolSize="2147000000" maxBufferSize="2147000000" maxReceivedMessageSize="2147000000" />
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="MetadataExchangeTcpBinding_IOAuth" openTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="2147000000" maxBufferSize="2147000000" maxReceivedMessageSize="2147000000">
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="http://10.10.10.10:1020/OAuth" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IOAuth" contract="svc.IOAuth" name="BasicHttpBinding_IOAuth" />
      <endpoint address="net.tcp://10.10.10.10:1021/OAuth" binding="netTcpBinding" bindingConfiguration="MetadataExchangeTcpBinding_IOAuth" contract="svc.IOAuth" name="MetadataExchangeTcpBinding_IOAuth" />
    </client>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <appSettings>
    <add key="departament" value="Lan" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

Everything works with a bang on Windows 7, but as soon as it comes to Windows XP, then there's trouble ...
the GAS-ASU.exe and GAS-ASU.exe.config file is created in 0 Kb, what could be the reason and how to fix it?
I will not refuse another way to transfer files from the server to the client.
Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Sotsky, 2016-04-08
@jekakmail

As far as I know, .NETFramework,Version=v4.5 and XP are not friends.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question