我使用VSTS 2008 + .Net + C#3.5開發WCF服務(自託管爲Windows服務)。從客戶端,我使用ChannelFactory連接到WCF服務。我的困惑是,當我將客戶端代碼從「public string response」更改爲「public string responseAliasName」時,responseAliasName的值爲null。但是當變回到變量名稱響應時,響應值是正確的(值是「hi WCF」)。爲什麼我的WCF客戶端獲得空結果?
我的困惑是,我認爲只要從客戶端和服務器端的佈局相同,變量名就不重要。任何想法有什麼不對?
服務器端代碼:
namespace Foo
{
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
[ServiceContract]
public interface IFoo
{
[OperationContract]
FooResponse Submit(string request);
}
[DataContract]
public class FooResponse
{
[DataMember]
public string response;
}
}
namespace Foo
{
// NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
public class FooImpl : IFoo
{
public FooResponse Submit(string request)
{
FooResponse foo = new FooResponse();
foo.response = "hi WCF";
return foo;
}
}
}
客戶端代碼:
namespace Foo
{
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
[ServiceContract]
public interface IFoo
{
[OperationContract]
FooResponse Submit(string request);
}
[DataContract]
public class FooResponse
{
[DataMember]
// public string responseAliasName;
public string response;
}
}
namespace FooTestClient1
{
class Program
{
static void Main(string[] args)
{
ChannelFactory<IFoo> factory = new ChannelFactory<IFoo>(
"IFoo");
IFoo f = factory.CreateChannel();
FooResponse response = f.Submit("Hi!");
return;
}
}
}
您的解決方案工作,很酷!謝謝ArsenMkrt! – George2 2009-07-16 09:40:39