我使用c#4.0版开发了一个Web服务(ASMX)。这只会将文件上传到我们的网络服务器。部署Web服务后,我使用.net v4.0创建一个win表单项目,然后创建我的Web服务的代理。之后,我测试文件上传过程,发现它正在工作。当我使用.net v2.0创建一个win表单应用程序并且当我在那里创建相同Web服务的代理然后我看到没有Reference.cs文件创建的代理时,问题就开始了。这就是为什么我无法调用该Web服务。当我尝试使用dotnet 2.0版创建代理时,我无法理解为什么没有创建Reference.cs文件。
所以告诉我是否有特定版本的问题。我想问题发生是因为我在dotnet v4.0上开发这个web服务,并在dotnet v2.0上创建代理。请解释为什么没有创建Reference.cs文件。还指导我如何解决这个问题。
这里我发布了我的网络服务代码。只是看看并告诉我有什么不对。
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class FileUploader : System.Web.Services.WebService
{
[WebMethod]
public string UploadFile(byte[] f, string fileName)
{
// the byte array argument contains the content of the file
// the string argument contains the name and extension
// of the file passed in the byte array
string uploadFolder = HttpContext.Current.Request.PhysicalApplicationPath + @"UPS_New\LabelImages\" + fileName;
try
{
// instance a memory stream and pass the
// byte array to its constructor
MemoryStream ms = new MemoryStream(f);
// instance a filestream pointing to the
// storage folder, use the original file name
// to name the resulting file
FileStream fs = new FileStream(uploadFolder, FileMode.Create);
// write the memory stream containing the original
// file as a byte array to the filestream
ms.WriteTo(fs);
// clean up
ms.Close();
fs.Close();
fs.Dispose();
// return OK if we made it this far
return "OK";
}
catch (Exception ex)
{
// return the error message if the operation fails
return ex.Message.ToString();
}
}
}
请指导我......我正在寻找建议。感谢
答案 0 :(得分:0)
这是version specific issue
,when the client is build below the version of service then service cannot be accessed in the client
。为了完成这项工作,build the service in 2.0 framework and then do the reference
。它将接受服务dll,因为它与客户端版本相同。
在您的情况下首先在2.0中构建服务,然后在您的客户端中使用在2.0中构建的代理。