服务契约和变量名称
我有WCF服务。我更改了数据契约中的变量名称,重建了服务,但没有重建客户端
之前,这是客户端的操作契约
[OperationContract(Name = "SubscribeWcfProvider")]
bool Subscribe(Guid subscriptionid);
之后,这是服务的操作契约
[OperationContract(Name = "SubscribeWcfProvider")]
bool Subscribe(Guid subscriberId);
现在,当客户端调用方法时,Guid始终为空。好像不能改变量名?这是为什么?
更新
请告诉我们幕后发生了什么?函数调用如何转换为消息?
I have WCF service. I have changed the name of the variable in datacontract, rebuilt service but did not rebuilt client
Before, this is operation contract for client
[OperationContract(Name = "SubscribeWcfProvider")]
bool Subscribe(Guid subscriptionid);
After, this is operation contract for service
[OperationContract(Name = "SubscribeWcfProvider")]
bool Subscribe(Guid subscriberId);
Now when client calls method the Guid is always null. It seems that I cannot change variable names? Why is that?
UPDATE
Please tell what happens behind the scene? How a function call is converted to message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您生成的代理(很可能)是在更改之前创建的,并且在更改之后不会重新生成。因此,代理基于 WSDL 对参数进行“硬编码”(我假设您使用 SOAP)。以下是 SOAP 消息的示例(取自此站点)。
在这种情况下,getBalance 方法需要帐户参数。如果服务器端发生变化并且客户端没有获得新合约并重建代理,则它将无法发送正确的参数。
请注意,如果您需要在代码中进行此类重大更改而不违反约定,则可以按以下方式在参数上应用 MessageParameterAttribute:
MSDN 显示您需要编辑的代码以及消息将被发送。
我建议您查看服务生成的 WSDL,以便了解幕后实际发生的情况。
The proxy you generated was (in all likelihood) created before the change and not regenerated after it. So the proxy "hardcoded" the parameters based on the WSDL (I'm assuming your using SOAP). Here is an example of a SOAP message (taken from this site).
In this case the getBalance method expects the account parameter. If this changes on the server side and the client doesn't get the new contract and rebuilds the proxy, it will not be able to send in the correct parameter.
Note that if you need to make breaking changes like these in your code without breaking the contract, you can apply the MessageParameterAttribute on the parameter in the following way:
There is a good example on that on MSDN which shows the code you need to edit as well as the message that will be sent.
I recommend that you take a look at your service's generated WSDL in order to see in action what's happening behind the scenes.
这取决于您的序列化选择。一般来说,如果参数的名称出现在序列化消息中,那么如果您在服务而不是客户端中更改其名称,则该名称将无法正确转换 - 几乎总是这种情况(SOAP、XML、JSON 等)。 )。
It depends on your serialization choice. In general, if the name of the parameter appears in the serialized message, it's not going to translate properly if you change its name in the service and not the client - and that is almost always the case (SOAP, XML, JSON, etc.).