我有一个简单的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 :(得分:1)
Ben,我认为您的服务引用存在一些问题,并且未正确生成代理类,因此long值可能会获得默认值0。 请检查以下项目