【发布时间】:2009-07-16 08:55:04
【问题描述】:
我正在使用 VSTS 2008 + .Net + C# 3.5 开发 WCF 服务(作为 Windows 服务自托管)。从客户端,我使用 ChannelFactory 连接到 WCF 服务。我的困惑是,当我将客户端代码从“公共字符串响应”更改为“公共字符串 responseAliasName”时,responseAliasName 的值为 null。但是当改回变量名响应时,响应值是正确的(值为“hi 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;
}
}
}
【问题讨论】:
标签: c# .net wcf visual-studio-2008