访问WinForm项目中的Web服务时出错

时间:2012-03-22 16:47:39

标签: c# winforms web-services namespaces service-reference

当我尝试使用我使用Windows应用程序编写的Web服务时,我遇到了错误。 Web服务似乎正常工作,我没有得到任何错误,但只要我在WinForms应用程序中将其添加为服务引用,我就会收到错误:

Error   1   The type name 'ServiceReference1' does not exist in the type 'CosmicInterface.CosmicInterface'

现在,我感觉它与命名空间有关但却无法弄清楚在哪里。这是我的Web服务代码片段:

namespace CosmicSvc
{
    [WebService(Namespace = "http://www.website.com")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class cosmic : System.Web.Services.WebService
    {
        [WebMethod()]
        public string etc....

服务文件名为'cosmic.asmx',我根本不确定。

这就是我的Windows应用程序中名为'CosmicInterface'的小代码。我所做的就是说“新项目”,然后添加了服务参考并尝试运行。那是我收到错误的时候。所以没有很多代码。我在几个名称下添加了服务引用,最后将其保留为默认的“ServiceRefrence1”。

namespace CosmicInterface
{
    public partial class CosmicInterface : Form
    {
        public CosmicInterface()
        {
            InitializeComponent();
        }
    }
}

2 个答案:

答案 0 :(得分:0)

好吧我明白了。事实证明我的命名空间和类名称相同。改变了课程并且有效 精细。

namespace CosmicInterface
{
        public partial class InterfaceForm : Form // <- I had to change this name to something different...
        {
            public InterfaceForm()
            {
                InitializeComponent();
            }
        }
}

答案 1 :(得分:0)

将WCF客户端应用程序的类名更改为与命名空间不同&#xA;更改封装WCF客户端应用程序类的命名空间(导致该类位于与引用不同的命名空间中)。

&# XA;
相关问题