使用 MessageContract 属性时出现问题:异常 ->结束元素“Body”来自命名空间“http://schemas.xmlsoap.org/soap/envelope/”预期的
我正在将 WSE3 Web 服务移至 WCF。但客户端是WSE3客户端。
所有操作契约都返回 MessageContract
类的实例。这适用于 2 项操作,但对于同一服务合同的一项操作却以某种方式失败。错误是:
签名或解密无效。
当我查看 WCF 跟踪文件时,我发现以下内容:
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'MyOperationName'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'MyOperationName' from namespace 'urn:MyProject:MyModule:2006:04:MyAuthorizationModule'.
我的观察是,当我使用 XmlRoot
属性时装饰响应类(而不是使用 MessageContract
属性),我没有收到此异常。但是,响应对象无法反序列化。即我可以在输入跟踪中看到 XML 响应,但由于预期的 XML 结构不匹配,服务调用在客户端返回 null
。
MessageContract
类具有只有一个公共属性 (MessageBodyMember
) 返回用 XmlRoot
属性修饰的另一个类的实例。该类(用 xmlRoot
修饰)有一个属性,该属性提供某个实体类的对象的 Collection
,该实体类中具有 XmlElement
属性。
我需要检查/验证哪些内容? 如果需要,我可以提供类代码片段。
I am moving my WSE3 web services to the WCF. But the client is WSE3 client.
All the Operation Contracts return an instance of the MessageContract
classes. This works for 2 operations but somehow fails for one operation of the same service contract. The error is:
The signature or decryption was invalid.
When I look into WCF trace file, I found the following:
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'MyOperationName'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'MyOperationName' from namespace 'urn:MyProject:MyModule:2006:04:MyAuthorizationModule'.
My observation is, when I use XmlRoot
attribute to decorate response class (instead of using MessageContract
attribute), I do not get this exception. However, response object cannot be deserialized. i.e. I can see the XML response in input trace but since the expected XML structure does not match, service call returns null
at client side.
The MessageContract
class has only one public property (MessageBodyMember
) which returns an instance of another class which is decorated with the XmlRoot
attribute. This class (which is decorated with xmlRoot
) has a property which gives the Collection
of objects of some entity class which has XmlElement
properties in it.
Which all things I need to check/verify?
I can provide class code snippets if required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
响应中使用的 MessageContract 没有问题。问题出在OperationContract 的输入参数上。
当我查看旧的 WSE3 Web 服务代理方法 (
WebMethod
) 并在 WCF 服务中为其创建OperationContract
时,我创建的OparationContract
执行了以下操作:不接受任何参数。在调查此问题时,我使用 svcutil.exe 从旧 WSE3 服务的 WSDL 创建 .NET 类。当我查看特定的
OperationContract
时,我发现我需要创建一个MessageContract
,它将用作OperationContract
的请求参数。因此,我创建了一个没有任何MessageBodyMember
的MessageContract
。当我使用它时,问题就解决了。显然,如果我们将
OperationContract
签名与 ASMXWebMethod
签名进行比较,它们不匹配,因为我们引入了输入参数。但这是有效的。我不知道如何以及为什么。 如果有人解释它为什么有效,那就太好了。There was no problem with the MessageContract which was used in response. The problem was with the input parameter to the OperationContract.
When I looked at the old WSE3 web service proxy method (
WebMethod
) and created theOperationContract
for it in WCF service, theOparationContract
I created did not accept any parameter.While investigating this issue, I used the
svcutil.exe
to create .NET classes from the WSDL of the old WSE3 service. When I looked into the specificOperationContract
I came to know that I need to create aMessageContract
which will be used as request parameter to theOperationContract
. So I created aMessageContract
without anyMessageBodyMember
. When I used it, the problem got resolved.Obviously, if we compare the
OperationContract
signature with the ASMXWebMethod
signature, they dont match since we have introduced input parameter. But this works. I do not know how and why. It would be great if someone explains why it works.