【发布时间】:2010-09-07 21:31:14
【问题描述】:
我有一个简单的 WCF 服务方法:
[OperationContract]
public SetupGameResult SetupGame(long player1Id, long player2Id, long myPlayerId)
{
if(player1Id == 0 || player2Id == 0 || myPlayerId == 0)
{
throw new ArgumentException();
}
... // other code
}
我只在 silverlight 应用程序中的一个地方调用此服务。这里:
if(player1Id == 0 || player2Id == 0 || myPlayerId == 0)
{
throw new ArgumentException();
}
// Setup Game
GameServiceClient gameService = new GameServiceClient();
gameService.SetupGameCompleted += new EventHandler<SetupGameCompletedEventArgs>(gameService_SetupGameCompleted);
gameService.SetupGameAsync(player1Id, player2Id, myPlayerId);
通常情况下,SetupGame永远不会在 myPlayerId = 0 时调用。但要确保我在调用服务方法之前进行检查。
问题是服务方法被正确调用一次,在第二次调用时它抛出参数异常,因为 myPlayerId = 0。
这很奇怪,因为我在调用之前检查它是否为 0。
会是什么问题?
编辑:
看来序列化/反序列化确实有问题。
但那会有什么原因?
编辑 2:
我在构建过程中收到以下警告。会不会是这个问题?
Warning 12 Client proxy generation for service 'Car_Motion.Web.Services.GameService' failed: Generating metadata files...
Warning: Unable to load a service with configName 'Car_Motion.Web.Services.GameService'. To export a service provide both the assembly containing the service type and an executable with configuration for this service.
Details:Either none of the assemblies passed were executables with configuration files or none of the configuration files contained services with the config name 'Car_Motion.Web.Services.GameService'.
Warning: No metadata files were generated. No service contracts were exported.
To export a service, use the /serviceName option. To export data contracts, specify the /dataContractOnly option. This can sometimes occur in certain security contexts, such as when the assembly is loaded over a UNC network file share. If this is the case, try copying the assembly into a trusted environment and running it.
提前致谢
【问题讨论】:
-
不正确的序列化/反序列化导致默认值。
-
好像。所有参数都是0。这真的很奇怪。
-
在哪里设置 mPlayerId?在您的支票和服务电话之间是否可以将其设置为零?
-
没有 myPlayerId 是调用服务的函数的参数。所以它不能从这个函数的范围之外改变,我在调用服务之前立即检查。真奇怪
标签: .net silverlight wcf