2013-03-22 80 views
0

我是在C#wpf中使用web服务的新手。我使用winforms下载了一个webservice示例。我设法从该winforms应用程序上传文件到我的服务器。现在我想将这个winforms功能与我现有的WPF应用程序合并。我无法找到如何让我的winforms项目中的Web引用下的“上传器”到我的WPF项目。这是一个Web引用“上传”包含代码:WPF从其他winforms项目添加文件上传服务

//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by a tool. 
//  Runtime Version:4.0.30319.18034 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
// ------------------------------------------------------------------------------ 

// 
// This source code was auto-generated by Microsoft.VSDesigner, Version 4.0.30319.18034. 
// 
#pragma warning disable 1591 

namespace TestUploader.Uploader { 
using System; 
using System.Web.Services; 
using System.Diagnostics; 
using System.Web.Services.Protocols; 
using System.Xml.Serialization; 
using System.ComponentModel; 


/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.17929")] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Web.Services.WebServiceBindingAttribute(Name="FileUploaderSoap", Namespace="http://tempuri.org/")] 
public partial class FileUploader : System.Web.Services.Protocols.SoapHttpClientProtocol { 

    private System.Threading.SendOrPostCallback UploadFileOperationCompleted; 

    private bool useDefaultCredentialsSetExplicitly; 

    /// <remarks/> 
    public FileUploader() { 
     this.Url = global::TestUploader.Properties.Settings.Default.TestUploader_Uploader_FileUploader; 
     if ((this.IsLocalFileSystemWebService(this.Url) == true)) { 
      this.UseDefaultCredentials = true; 
      this.useDefaultCredentialsSetExplicitly = false; 
     } 
     else { 
      this.useDefaultCredentialsSetExplicitly = true; 
     } 
    } 

    public new string Url { 
     get { 
      return base.Url; 
     } 
     set { 
      if ((((this.IsLocalFileSystemWebService(base.Url) == true) 
         && (this.useDefaultCredentialsSetExplicitly == false)) 
         && (this.IsLocalFileSystemWebService(value) == false))) { 
       base.UseDefaultCredentials = false; 
      } 
      base.Url = value; 
     } 
    } 

    public new bool UseDefaultCredentials { 
     get { 
      return base.UseDefaultCredentials; 
     } 
     set { 
      base.UseDefaultCredentials = value; 
      this.useDefaultCredentialsSetExplicitly = true; 
     } 
    } 

    /// <remarks/> 
    public event UploadFileCompletedEventHandler UploadFileCompleted; 

    /// <remarks/> 
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/UploadFile", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 
    public string UploadFile([System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] f, string fileName) { 
     object[] results = this.Invoke("UploadFile", new object[] { 
        f, 
        fileName}); 
     return ((string)(results[0])); 
    } 

    /// <remarks/> 
    public void UploadFileAsync(byte[] f, string fileName) { 
     this.UploadFileAsync(f, fileName, null); 
    } 

    /// <remarks/> 
    public void UploadFileAsync(byte[] f, string fileName, object userState) { 
     if ((this.UploadFileOperationCompleted == null)) { 
      this.UploadFileOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUploadFileOperationCompleted); 
     } 
     this.InvokeAsync("UploadFile", new object[] { 
        f, 
        fileName}, this.UploadFileOperationCompleted, userState); 
    } 

    private void OnUploadFileOperationCompleted(object arg) { 
     if ((this.UploadFileCompleted != null)) { 
      System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); 
      this.UploadFileCompleted(this, new UploadFileCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); 
     } 
    } 

    /// <remarks/> 
    public new void CancelAsync(object userState) { 
     base.CancelAsync(userState); 
    } 

    private bool IsLocalFileSystemWebService(string url) { 
     if (((url == null) 
        || (url == string.Empty))) { 
      return false; 
     } 
     System.Uri wsUri = new System.Uri(url); 
     if (((wsUri.Port >= 1024) 
        && (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) { 
      return true; 
     } 
     return false; 
    } 
} 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.17929")] 
public delegate void UploadFileCompletedEventHandler(object sender, UploadFileCompletedEventArgs e); 

/// <remarks/> 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.17929")] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
public partial class UploadFileCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { 

    private object[] results; 

    internal UploadFileCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
      base(exception, cancelled, userState) { 
     this.results = results; 
    } 

    /// <remarks/> 
    public string Result { 
     get { 
      this.RaiseExceptionIfNecessary(); 
      return ((string)(this.results[0])); 
     } 
    } 
} 
} 

#pragma warning restore 1591 

除此之外,我不知道如何设置从的WinForms迁移到WPF。在我的WinForms:

<configSections> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="TestUploader.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </sectionGroup> 
</configSections> 
<applicationSettings> 
    <TestUploader.Properties.Settings> 
     <setting name="TestUploader_Uploader_FileUploader" serializeAs="String"> 
      <value>http://xxx/videolibrary/Upload/FileUploader.asmx</value> 
     </setting> 
    </TestUploader.Properties.Settings> 
</applicationSettings> 

我的问题中最大的部分是,我不完全理解的结构,以及如何Web引用功能。这可能是我为什么可能会错误地表述我的问题的原因。

- 编辑 -

当我使用添加服务引用引用似乎比我的WinForms原来的基准不同。在左边我的winforms树,在我的wpf树上

http://dl.dropbox.com/u/8308826/screen.jpg

+0

如果是这样的话,你可以使用visual studio,你应该可以在ide中添加一个服务引用。这将为您创建服务参考类。 – TheKingDave 2013-03-22 12:28:26

回答

1

您应该将其添加为服务参考。 Web引用是旧版本的WCF服务,它存在于.NET 2中。在您的WPF项目中,您应该添加服务引用。

阅读http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx了解其差异以及如何使用它们。

+0

谢谢你的回复。如果我在我的WPF项目中单击添加服务引用,则输入地址:http://xxx/videolibrary/Upload/FileUploader.asmx。在服务框中只显示FileUploader。 winforms项目中的原始引用称为uploader,其中包含FileUploader,Fileuploadercompleted和Fileuploadercompletedargs。现在有些失踪了吗? – user1766412 2013-03-22 12:36:04

+0

我认为我的发现发现,在我尝试创建新的文件上传器时,IDE无法在testapplication.uploader中找到fileuploader,“TestApplication.Uploader.FileUploader srv”是否还有其他任何我缺少的内容? – user1766412 2013-03-22 12:40:02

+0

@ user1766412当您将服务添加到您的服务中时,它只会根据您的服务设置生成一个proxi课程。一般来说,Web ref和service ref通过内部的不同类来做同样的事情。 – Alex 2013-03-22 12:45:12

相关问题