有什么解决办法吗

有什么解决办法吗

本文介绍了在客户端,WCF 操作合约的返回值为 null !有什么解决办法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 WCF 服务中有一个操作契约,它返回一个实际上是消息契约的类的实例.(不是数据合同).消息合约具有属性 > [MessageBodyMember]

I have an Operation Contract in my WCF service which returns an instance of the class which is actually a Message Contract. (Not Data Contract). The Message Contract has properties with attribute > [MessageBodyMember]

[MessageContract(WrapperName="AuthorizarionResponse", IsWrapped="true")]
public class AuthorizationResponse
{
  [MessageBodyMember] public string role {get;set;};
  [MessageBodyMember] public Organization organization {get; set;};
}

[ServiceContract]
interface IAuthorization
{
    [OperationContract]
    public AuthoriztionResponse GetAuthorizationResult(AuthorizationRequestMessage request);

}

Organization 类使用 XmlSerializer.它不使用 DataContract,因为我希望从现有的 ASMX 客户端使用 WCF 服务.当我调试服务并看到操作契约方法中的返回值时,我可以通过这个操作契约看到我想从服务中返回的所有内容.

Organization class uses the XmlSerializer. It does not use DataContract because I want WCF service to be used from existing ASMX clients.When I debug the service and see the return value in the Operation Contract method, i can see everything which i want to return from the service through this operation contract.

但在客户端,我得到空值!

But at the client side, I get null value!

一切都结束了,没有任何异常/错误.Fiddler2 没有给出任何红色/错误标记!会出什么问题?

Everything is ending without any exception/error. Fiddler2 does not give any red/error marks!What would be going wrong?

推荐答案

问题是 Service 发送的回复 soap 消息未按客户端合同代码的预期形成.序列化器根据客户端应用程序中Proxy代码中定义的Contract来解析Soap消息,但是,如果接收到的soap消息不符合预期,序列化器会悄悄地跳过内容并继续前进.所以,没有错误,也没有填充对象,因为序列化程序没有找到预期的内容.

The issue is Service sending the reply soap message not formed as expected by client Contract code. The serializer parses the Soap message based on Contract defined in Proxy code in client application, however, if the soap message received is not as expected, serializer Silently skips the content and moves forward. So, there is no error and also object is not filled because serializer didn't find expected contents.

因此,您需要确定客户期望如何形成肥皂消息..

So, you'd need to identify how client expects soap message formed..

这篇关于在客户端,WCF 操作合约的返回值为 null !有什么解决办法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:11