для загрузки файла с клиента на сервер вы можете использовать следующий код: service
[ServiceContract(SessionMode=SessionMode.Required, CallbackContract=typeof(IFreeBoxServiceCallBack))]
public interface IFreeBoxService
{
[OperationContract(IsOneWay = true)]
void sendFile(byte[] bytes, int offset, int count);
[OperationContract(IsOneWay = true)]
void sendFileName(string fileName);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)]
public class FreeBoxService:IFreeBoxService
{
string path = "D:\\repository\\";
string fileName = "";
IFreeBoxServiceCallBack callBack = null;
public FreeBoxService()
{
callBack = OperationContext.Current.GetCallbackChannel<IFreeBoxServiceCallBack>();
}
public void sendFileName(string fileName)
{
this.fileName = fileName;
}
public void sendFile(byte[] bytes, int offset, int count)
{
using (FileStream fileStream = new FileStream(path + fileName, FileMode.Append, FileAccess.Write))
{
fileStream.Write(bytes, offset, count);
fileStream.Close();
fileStream.Dispose();
}
}}
клиент:
private void sendFileToServer()
{
FileStream fs = new FileStream(fullName,FileMode.Open,FileAccess.Read);
int bytesRead = 0;
bytes = new byte[15000];
proxy.sendFileName("someFile.xml");
while ((bytesRead = fs.Read(bytes, 0, 15000))>0)
{
proxy.sendFile(bytes, 0, bytesRead);
}
fs.Close();
fs.Dispose();
}
.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="FreeBoxServiceLib.FreeBoxService" behaviorConfiguration="MyServiceBehevior">
<endpoint address="" contract="FreeBoxServiceLib.IFreeBoxService"
binding="netTcpBinding">
</endpoint>
<endpoint address="MEX" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/FreeBoxService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehevior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
всегда лучше передать массив байтов. Я думаю, не нужно описывать функции обратного вызова?