我正在尝试在我的应用程序中使用WCF Web服务,但是在添加服务引用和相应的using语句之后,我无法编译我的代码,并且在11行中出现以下错误11次数:
Error 7 The type name 'SignOnService' does not exist in the type 'FTXService.FTXService' C:\Users\bdugan\documents\visual studio 2010\Projects\FTXService\FTXService\Service References\SignOnService\Reference.cs 130 20 FTXService
我知道服务存在,因为我过去在PHP中使用它,但我似乎无法弄清楚它为什么不起作用。这是Reference.cs:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.237
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace FTXService.SignOnService {
using System.Runtime.Serialization;
using System;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="SimpleItem", Namespace="http://schemas.datacontract.org/2004/07/")]
[System.SerializableAttribute()]
public partial class SimpleItem : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private bool AuthenticatedField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string[] ContractIDsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string MessageStringField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string[] OwnerIDsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private bool PasswordChangedField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public bool Authenticated {
get {
return this.AuthenticatedField;
}
set {
if ((this.AuthenticatedField.Equals(value) != true)) {
this.AuthenticatedField = value;
this.RaisePropertyChanged("Authenticated");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string[] ContractIDs {
get {
return this.ContractIDsField;
}
set {
if ((object.ReferenceEquals(this.ContractIDsField, value) != true)) {
this.ContractIDsField = value;
this.RaisePropertyChanged("ContractIDs");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string MessageString {
get {
return this.MessageStringField;
}
set {
if ((object.ReferenceEquals(this.MessageStringField, value) != true)) {
this.MessageStringField = value;
this.RaisePropertyChanged("MessageString");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string[] OwnerIDs {
get {
return this.OwnerIDsField;
}
set {
if ((object.ReferenceEquals(this.OwnerIDsField, value) != true)) {
this.OwnerIDsField = value;
this.RaisePropertyChanged("OwnerIDs");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public bool PasswordChanged {
get {
return this.PasswordChangedField;
}
set {
if ((this.PasswordChangedField.Equals(value) != true)) {
this.PasswordChangedField = value;
this.RaisePropertyChanged("PasswordChanged");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="SignOnService.ISignOn")]
public interface ISignOn {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISignOn/Authentication_Complex", ReplyAction="http://tempuri.org/ISignOn/Authentication_ComplexResponse")]
FTXService.SignOnService.SimpleItem Authentication_Complex(string UserName, string Password);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISignOn/Authentication_Simple", ReplyAction="http://tempuri.org/ISignOn/Authentication_SimpleResponse")]
FTXService.SignOnService.SimpleItem Authentication_Simple(string Parameter1, string Parameter2);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISignOn/Authentication_ChangePassword", ReplyAction="http://tempuri.org/ISignOn/Authentication_ChangePasswordResponse")]
FTXService.SignOnService.SimpleItem Authentication_ChangePassword(string Parameter1, string Parameter2, string Parameter3);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISignOn/Authentication_Reset", ReplyAction="http://tempuri.org/ISignOn/Authentication_ResetResponse")]
FTXService.SignOnService.SimpleItem Authentication_Reset(string Parameter1);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface ISignOnChannel : FTXService.SignOnService.ISignOn, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class SignOnClient : System.ServiceModel.ClientBase<FTXService.SignOnService.ISignOn>, FTXService.SignOnService.ISignOn {
public SignOnClient() {
}
public SignOnClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public SignOnClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public SignOnClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public SignOnClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
public FTXService.SignOnService.SimpleItem Authentication_Complex(string UserName, string Password) {
return base.Channel.Authentication_Complex(UserName, Password);
}
public FTXService.SignOnService.SimpleItem Authentication_Simple(string Parameter1, string Parameter2) {
return base.Channel.Authentication_Simple(Parameter1, Parameter2);
}
public FTXService.SignOnService.SimpleItem Authentication_ChangePassword(string Parameter1, string Parameter2, string Parameter3) {
return base.Channel.Authentication_ChangePassword(Parameter1, Parameter2, Parameter3);
}
public FTXService.SignOnService.SimpleItem Authentication_Reset(string Parameter1) {
return base.Channel.Authentication_Reset(Parameter1);
}
}
}
有什么想法吗?
答案 0 :(得分:1)
服务中有一个名为FTXService
的类,嵌入在名为FTXService
的名称空间中。从该服务生成客户端代理时,Visual Studio的服务生成器会混乱。它生成的代码似乎引用了servicerefence中使用的重新发生的命名空间,而不是要调用的服务类方法。
要解决此问题,请将服务实现的类重命名为(例如)FTXServiceImpl
并重新生成客户端代理(在客户端项目中删除并添加服务引用)。
答案 1 :(得分:0)
在Visual Studio中使用“添加服务引用”对话框时,通常会要求您指定命名空间。默认情况下为ServiceReference1
。它还生成通常最终得到的强类型代理客户端类。所以客户端代理可能看起来像这样:
using (var client = new ServiceReference1.SomeNamespace.SignOnServiceClient())
{
...
}
只需右键单击生成的服务代理并浏览源代码即可查看确切创建的类。
答案 2 :(得分:0)
根据您发布的Reference.cs,服务客户端名为SignOnClient,因此您需要以下内容:
var client = new SignOnClient();
或完全符合资格:
var client = new FTXService.SignOnService.SignOnClient();
换句话说,命名空间中不存在类型SignOnService
(这是错误告诉你的),但SignOnClient
确实存在。