C# 是否要以visual studio 2013中另一个解决方案中的格式从文本框访问数据?
我有两种解决方案,即传输服务和发送方。TranferService具有WCF服务,并且必须承载该服务。在发件人解决方案中,我有windows窗体应用程序。在该表单中,我使用按钮浏览并选择文件,使用文本框显示选定的文件路径,使用另一个按钮(发送)通过WCF服务传输该文件。但我无法访问传输解决方案中的文本框值。它显示“该名称在当前上下文中不存在”。C# 是否要以visual studio 2013中另一个解决方案中的格式从文本框访问数据?,c#,winforms,wcf,C#,Winforms,Wcf,我有两种解决方案,即传输服务和发送方。TranferService具有WCF服务,并且必须承载该服务。在发件人解决方案中,我有windows窗体应用程序。在该表单中,我使用按钮浏览并选择文件,使用文本框显示选定的文件路径,使用另一个按钮(发送)通过WCF服务传输该文件。但我无法访问传输解决方案中的文本框值。它显示“该名称在当前上下文中不存在”。 转帐服务代码 using System; using System.Collections.Generic; using System.Linq; us
转帐服务代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace TransferService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "TransferService" in both code and config file together.
public class TransferService : ITransferService
{
public File DownloadDocument()
{
File file = new File();
String path = txtSelectFilePath.Text;
file.Content = System.IO.File.ReadAllBytes(@path);
//file.Name = "ImagingDevices.exe";
return file;
}
}
}
我在这条线上遇到了错误String path = txtSelectFilePath.Text;
form.cs的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sender
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Browse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtSelectFilePath.Text = openFileDialog1.FileName;
}
}
private void Send_Click(object sender, EventArgs e)
{
TransferService.TransferServiceClient client = new TransferService.TransferServiceClient();
TransferService.File file = client.DownloadDocument();
System.IO.File.WriteAllBytes(@"C:\DownloadedFiles\" + file.Name, file.Content);
MessageBox.Show(file.Name + " is downloaded");
}
}
}
ITransferService.cs的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace TransferService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ITransferService" in both code and config file together.
[ServiceContract]
public interface ITransferService
{
[OperationContract]
File DownloadDocument();
}
[DataContract]
public class File
{
[DataMember]
public string Name { get; set; }
[DataMember]
public byte[] Content { get; set; }
}
}
Thanx提前了很多………然后为类创建一个构造函数,该构造函数接收一个作为字符串的路径,如下所示:
public class TransferService : ITransferService
{
private string _path;
public TransferService(string path) {
_path = path
}
public File DownloadDocument()
{
File file = new File();
//String path = txtSelectFilePath.Text;
file.Content = System.IO.File.ReadAllBytes(_path);
//file.Name = "ImagingDevices.exe";
return file;
}
}
然后是form.cs
TransferService.TransferServiceClient client = new TransferService.TransferServiceClient(txtSelectFilePath.Text);
如果我正确理解您的问题:您不能。我认为最好在DownloadDocument(字符串路径)中添加一个字符串参数,并在调用ittyms进行回复时传递路径。。。。。。George sir当我试图传递参数时,出现以下错误:-“TransferService.TransferService”未实现接口成员“TransferService.ITransferService.DownloadDocument()”当我创建WCF服务并实现该接口时,它生成了没有参数的函数。这是原因吗?是的,但我认为你可以通过创建一个构造函数来克服这个问题…请使用codeTransferService.File File=client.DownloadDocument(txtSelectFilePath.Text)查看我的awnser;当我尝试此操作时,它会给我错误,如方法DownloadDocument没有重载。是否需要编辑ITransferService.cs此文件也…?抱歉,已修复,没有,我创建此文件是为了实现接口而不需要更改它,但这取决于您的决定