我是WCF的新手,所以我真的很感激,如果你可以回答儘可能詳細:)我有一個WCF服務庫和WPF應用程序(誰是客戶端)。想要的結果是一個應用程序,使文件共享之間的連接clients.I建立真的基本WCF服務庫與一個方法:通過WCF文件傳輸
[ServiceContract]
public interface IFileService
{
[OperationContract]
byte[] GetFile(string fullPath);
}
而且實現了這個方法是這樣的:
public class FileService : IFileService
{
public byte[] GetFile(string fullPath)
{
return System.IO.File.ReadAllBytes(fullPath);
}
}
這是WPF客戶端項目App.config文件:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IFileService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:9355/TankusFileTransferService/Service/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFileService"
contract="TankusFileService.IFileService" name="WSHttpBinding_IFileService">
<identity>
<userPrincipalName value="GIL-LAPTOP\Gil" />
</identity>
</endpoint>
</client>
</system.serviceModel>
這是從主窗口WPF AP代碼折戟:
public partial class MainWindow : Window
{
ServiceHost sh;
TankusFileService.FileServiceClient fsc;
public MainWindow()
{
InitializeComponent();
}
private void btn_Connect_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("http://127.0.0.1:1234/");
sh = new ServiceHost(typeof(TankusFileTransferService.FileService), uri);
sh.Open();
lbl_Listener.Content = sh.Description.Endpoints[0].Address.ToString();
}
private void btn_Disconnect_Click(object sender, RoutedEventArgs e)
{
sh.Close();
lbl_Listener.Content = string.Empty;
}
private void btn_GetFile_Click(object sender, RoutedEventArgs e)
{
fsc = new TankusFileService.FileServiceClient();
fsc.Endpoint.Address = new EndpointAddress("http://127.0.0.1:1234/");
fsc.Endpoint.Binding = new BasicHttpBinding();
byte[] bytes = fsc.GetFile(@"D:\mika.txt");
System.IO.File.WriteAllBytes(@"D:\mika_new.txt", bytes);
}
}
當我按下連接按鈕並初始化ServiceHost對象,以便它可以開始監聽我按下getFile按鈕。當調用GetFile()函數時,會引發TimeoutException。爲什麼是這樣?我甚至在正確的方式完成我想要的應用程序?謝謝:)
發佈您的頻道的web.config設置。您可能需要增加尺寸。 – Mutant 2012-03-17 16:49:48