Problem while using MessageContract attribute : Exception -> End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected

江枫思渺然 提交于 2019-12-12 02:44:18

问题


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.


回答1:


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 the OperationContract for it in WCF service, the OparationContract 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 specific OperationContract I came to know that I need to create a MessageContract which will be used as request parameter to the OperationContract. So I created a MessageContract without any MessageBodyMember. When I used it, the problem got resolved.

Obviously, if we compare the OperationContract signature with the ASMX WebMethod 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.



来源:https://stackoverflow.com/questions/6263310/problem-while-using-messagecontract-attribute-exception-end-element-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!