EnterpriseData
20.10.2017

( )

! " ", 2.3.1.62.

, . - 1ѻ. -, , :

. <From> XML ( <Confirmation>). <To> ( ϻ).

- EnterpriseDataExchange

- EnterpriseDataExchange .

- ( XML ):

  1. TestConnection.
  2. XML PutFilePart. PutFilePart, PartNumber, . PartNumber , .
  3. , PutData.
  4. PutData PutDataActionResult. - ; PutDataActionResult , , 5 , Completed.
C#

, :

.

, , .

( ):

static void PutData2WebService_ExchangePlan(string serviceURL, string user, string password, string peerCode, string exchangePlanName, string fileName)
{
EnterpriseDataExchange.EnterpriseDataExchange_1_0_1_1 edDataExchange = new EnterpriseDataExchange.EnterpriseDataExchange_1_0_1_1();
edDataExchange.Url = serviceURL;
edDataExchange.Credentials = new System.Net.NetworkCredential(user, password);
string result = edDataExchange.Ping();
System.Console.WriteLine("Ping OK");
string errorMessage;
bool testConnection = edDataExchange.TestConnection(exchangePlanName, peerCode, out errorMessage);
if (testConnection)
{
// ZIP- -
bool singleFile = fileName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase);
string fileId = Guid.NewGuid().ToString();
if (singleFile)
{
byte[] partData = System.IO.File.ReadAllBytes(fileName);
// 0
result = edDataExchange.PutFilePart(fileId, 0, partData, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
}
else
{
//
int partNumber = 1;
//, (*.001, *.002 ..)
string filePath = fileName + "." + (partNumber).ToString("d3");
while (System.IO.File.Exists(filePath))
{
System.Console.WriteLine("Reading from: " + filePath);
byte[] partData = System.IO.File.ReadAllBytes(filePath);
string putFilePartResult = edDataExchange.PutFilePart(fileId, partNumber, partData, out errorMessage);
if (errorMessage != string.Empty)
{
System.Console.WriteLine("PutFilePart error: " + errorMessage);
return;
}
filePath = fileName + "." + (++partNumber).ToString("d3");
}
}
string operationId;
result = edDataExchange.PutData(exchangePlanName, peerCode, fileId, out operationId, out errorMessage);
if (errorMessage != string.Empty)
{
System.Console.WriteLine("PutData error: " + errorMessage);
return;
}

string putDataActionResult = edDataExchange.PutDataActionResult(operationId, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
while (putDataActionResult == "Active")
{
// 5 -
putDataActionResult = edDataExchange.PutDataActionResult(operationId, out errorMessage);
System.Threading.Thread.Sleep(5000);
System.Console.WriteLine("PutDataActionResult: " + putDataActionResult);
}
}
else
{
System.Console.WriteLine("TestConnection fails: " + errorMessage);
}
}


:

PutData2WebService_ExchangePlan("http://server/1c_app/ws/EnterpriseDataUpload_1_0_1_1", 
"Administrator",
"pass@word",
"ZZ",
"",
"c:\exchange\data.zip");

Java:

static void putData2WebService_ExchangePlan(String serviceURL, String user, String password, String peerCode, String exchangePlanName, String fileName)
{
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
});

URL url = null;

try {
url = new URL(serviceURL);
} catch (MalformedURLException e) {
e.printStackTrace();
}

EnterpriseDataExchange1011 ss;
ss = new EnterpriseDataExchange1011(url,
EnterpriseDataExchange1011.SERVICE);

EnterpriseDataExchange1011PortType port = ss.getEnterpriseDataExchange1011Soap12();
System.out.println("Invoking ping...");
port.ping();
System.out.println("Ping Ok");

Holder<String> outString = new Holder<String>();
Boolean testConnectionOk = port.testConnection(exchangePlanName, peerCode, outString);
if (testConnectionOk)
{
// ZIP- -
Boolean singleFile = fileName.toLowerCase().endsWith(".zip");
String fileId = UUID.randomUUID().toString();
String strResult;

if (singleFile)
{
Path path = Paths.get(fileName);
byte[] data;

try
{
data = Files.readAllBytes(path);
}
catch (Exception e)
{
System.err.println("Exception when open file " + path);
return;
}

// 0
strResult = port.putFilePart(fileId, 0, data, outString);
if (!outString.value.isEmpty())
{
System.err.println("PutFilePart error: " + outString);
return;
}
}
else
{
//
int partNumber = 1;

//, (*.001, *.002 ..)
Path filePath = Paths.get(fileName + "." + String.format("%03d", partNumber));

while (Files.exists(filePath))
{
System.out.println("reading from " + filePath);

byte[] data;

try
{
data = Files.readAllBytes(filePath);
}
catch (Exception e)
{
System.err.println("Exception when open file " + filePath);
return;
}

strResult = port.putFilePart(fileId, partNumber, data, outString);
if (!outString.value.isEmpty())
{
System.err.println("PutFilePart error: " + outString.value);
return;
}

filePath = Paths.get(fileName + "." + String.format("%03d", ++partNumber));
}
}

Holder<String> operationId = new Holder<String>();
strResult = port.putData(exchangePlanName, peerCode, fileId, operationId, outString);
if (!outString.value.isEmpty())
{
System.err.println("PutData error: " + outString.value);
return;
}

strResult = port.putDataActionResult(operationId.value, outString);
if (!outString.value.isEmpty())
{
System.err.println("putDataActionResult error: " + outString.value);
return;
}
else
{
System.out.println("putDataActionResult: " + strResult);

while ("Active".equals(strResult))
{
// 5 -
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
//ignore
}

strResult = port.putDataActionResult(operationId.value, outString);

if (!outString.value.isEmpty())
{
System.err.println("putDataActionResult error: " + outString.value);
return;
}
System.out.println("putDataActionResult: " + strResult);
}
}
}
else
{
System.err.println("Connection failed, reason: " + outString.value);
}
}

-:

  1. TestConnection.
  2. PrepareDataForGetting.
  3. PrepareDataActionResult PrepareDataForGetting. PrepareDataActionResult , PrepareDataForGetting ( Status Active), PrepareDataActionResult (, 5 .) , PrepareDataForGetting ( Status Active).
  4. PrepareDataForGetting , GetDataPart.
  5. , ConfirmGettingFile.
C#

, :

.

, , .

:

static void GetDataFromWebService_ExchangePlan(string serviceURL, string user, string password, string peerCode, string exchangePlanName, string fileName)
{
EnterpriseDataExchange.EnterpriseDataExchange_1_0_1_1 edDataExchange = new EnterpriseDataExchange.EnterpriseDataExchange_1_0_1_1();
edDataExchange.Url = serviceURL;
edDataExchange.Credentials = new System.Net.NetworkCredential(user, password);
string result = edDataExchange.Ping();
string errorMessage;
bool testConnection = edDataExchange.TestConnection(exchangePlanName, peerCode, out errorMessage);
if (testConnection)
{
string operationId;
// 1024 (1)
result = edDataExchange.PrepareDataForGetting(exchangePlanName, peerCode, 1024, out operationId, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
EnterpriseDataExchange.PrepareDataOperationResult operationResult = edDataExchange.PrepareDataActionResult(operationId, out errorMessage);

if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
while (operationResult.Status == "Active")
{
System.Console.WriteLine("Status " + operationResult.Status + ", waiting...");
System.Threading.Thread.Sleep(5000);
operationResult = edDataExchange.PrepareDataActionResult(operationId, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine("PrepareDataActionResult out string: " + errorMessage);
return;
}
}
System.Console.WriteLine("Status: " + operationResult.Status);

int partCount = operationResult.PartCount;
for (int i = 1; i <= partCount; i++)
{
byte[] data = edDataExchange.GetDataPart(operationResult.FileID, i, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
string fileName2Save = (partCount == 1) ? fileName + ".zip" : fileName + "." + i.ToString("d3");
System.IO.File.WriteAllBytes(fileName2Save, data);
}
result = edDataExchange.ConfirmGettingFile(operationResult.FileID, true, out errorMessage);
System.Console.WriteLine("GetDataFromWebService completed");
}
else
{
System.Console.WriteLine(errorMessage);
}
}

:

GetDataFromWebService_ExchangePlan("http://server/1c_app/ws/EnterpriseDataUpload_1_0_1_1",
"Administrator", "pass@word", "ZZ", "",
"c:\exchange\data");

Java:

static void GetDataFromWebService_ExchangePlan(string serviceURL, string user, string password, string peerCode, string exchangePlanName, string fileName)
{
EnterpriseDataExchange.EnterpriseDataExchange_1_0_1_1 edDataExchange = new EnterpriseDataExchange.EnterpriseDataExchange_1_0_1_1();
edDataExchange.Url = serviceURL;
edDataExchange.Credentials = new System.Net.NetworkCredential(user, password);
string result = edDataExchange.Ping();
string errorMessage;
bool testConnection = edDataExchange.TestConnection(exchangePlanName, peerCode, out errorMessage);
if (testConnection)
{
string operationId;
// 1024 (1)
result = edDataExchange.PrepareDataForGetting(exchangePlanName, peerCode, 1024, out operationId, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
EnterpriseDataExchange.PrepareDataOperationResult operationResult = edDataExchange.PrepareDataActionResult(operationId, out errorMessage);

if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
while (operationResult.Status == "Active")
{
System.Console.WriteLine("Status " + operationResult.Status + ", waiting...");
System.Threading.Thread.Sleep(5000);
operationResult = edDataExchange.PrepareDataActionResult(operationId, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine("PrepareDataActionResult out string: " + errorMessage);
return;
}
}
System.Console.WriteLine("Status: " + operationResult.Status);

int partCount = operationResult.PartCount;
for (int i = 1; i <= partCount; i++)
{
byte[] data = edDataExchange.GetDataPart(operationResult.FileID, i, out errorMessage);
if (errorMessage != String.Empty)
{
System.Console.WriteLine(errorMessage);
return;
}
string fileName2Save = (partCount == 1) ? fileName + ".zip" : fileName + "." + i.ToString("d3");
System.IO.File.WriteAllBytes(fileName2Save, data);
}
result = edDataExchange.ConfirmGettingFile(operationResult.FileID, true, out errorMessage);
System.Console.WriteLine("GetDataFromWebService completed");
}
else
{
System.Console.WriteLine(errorMessage);
}
}