WCF服务引用无法编译

时间:2011-11-30 20:56:16

标签: wcf

我目前有一个简单的WCF服务,其操作如下:

[OperationContract]
int InsertApplication(Application application);

应用程序参数定义如下:

[DataContract]
public class Application
{
    int test = 0;

    [DataMember]
    public int Test
    {
        get { return test; }
        set { test = value; }
    }
}

此服务正在具有命名空间SpringstoneColoAgent的Windows服务中使用。我添加了一个没有问题的服务引用OfficeInternalService。调用服务方法的代码如下:

 Application application = new Application();//= ConvertToApp(app);
 application.Test = 1;
 int oracleID = client.InsertApplication(application);

但是,visual studio告诉我“应用程序”是一个无效的参数。在进一步的研究中,我试着建立。我收到一堆指向Reference.cs文件的错误。查看此文件,我确定所有错误都围绕使用以下代码:

SpringstoneColoAgent.OfficeInternalService._ 

在服务引用名称下尝试引用的任何内容都不正确。例如,这段代码给出了一个错误:

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOfficeInternalService/InsertApplication", ReplyAction="http://tempuri.org/IOfficeInternalService/InsertApplicationResponse")]
int InsertApplication(SpringstoneColoAgent.OfficeInternalService.Application application);

如果我没有完全限定命名空间并删除SpringstoneColoAgent.OfficeInternalService。所以代码看起来像这样:

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOfficeInternalService/InsertApplication", ReplyAction="http://tempuri.org/IOfficeInternalService/InsertApplicationResponse")]
int InsertApplication(Application application);

这将解决错误。我在任何地方重复这一点,我可以找到错误,一切都编译好了。缺点是,每次我对WCF服务进行更改并需要更新服务引用时,它都会丢失这些更改,我必须返回并更改它们。

我猜我在这里错过了一些东西,如果有人有任何指示或遇到类似的情况,我很好奇。

感谢您的任何建议!

1 个答案:

答案 0 :(得分:2)

Application类是已知的.NET类型:http://msdn.microsoft.com/en-us/library/system.windows.forms.application.aspx。尝试使用不同的类名来避免名称冲突。

还尝试避免datacontract中的int私有成员。因为它不是数据库,所以它不会在WSDL中公开,并且客户端上生成的代理类不知道此私有成员。这也可能导致问题。