从asmx客户端获取空值,该客户端以迁移(从asmx到wcf)服务为目标

时间:2012-11-20 08:49:59

标签: wcf asmx

我有一个ASMX服务,我迁移到wcf(使用basicHttpBinding),现在我使用旧客户端(whcih使用wsdl.exe生成代理)来命中服务。我可以看到调用到达服务并且服务返回非null对象,但是asmx客户端接收的返回值为null。

为什么会发生这种情况的原因以及如何进一步调试?

  // This is my webservice 

   [ServiceContract(Namespace = "http://tempuri.org/ManagementWebService")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class ManagementService
    {
        [OperationContractAttribute(Action = "http://tempuri.org/ManagementWebService/GetViewSummaryForCurrentUser", ReplyAction = "*")]
        [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
        [XmlSerializerFormatAttribute()]
        [CLSCompliant(false)]
        [WebMethod]
        public virtual ViewSummaryList GetViewSummaryForCurrentUser()
        {
            return new ViewSummaryList();
        }
}


// This is the client side code which receives a null value.
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ManagementWebService/GetVi" +
            "ewSummaryForCurrentUser", RequestNamespace="http://tempuri.org/ManagementWebService", ResponseNamespace="http://tempuri.org/ManagementWebService", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("Views")]
        public ViewSummaryList GetViewSummaryForCurrentUser() {
            object[] results = this.Invoke("GetViewSummaryForCurrentUser", new object[0]);
            return ((ViewSummaryList)(results[0]));
        }

1 个答案:

答案 0 :(得分:0)

想出来,基本上肥皂反应不正确地生成

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetViewSummaryForCurrentUserResponse xmlns="http://tempuri.org/ManagementWebService"><GetViewSummaryForCurrentUserResult/></GetViewSummaryForCurrentUserResponse></s:Body></s:Envelope>

而不是

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetViewSummaryForCurrentUserResponse xmlns="http://tempuri.org/ManagementWebService"><Views /></GetViewSummaryForCurrentUserResponse></soap:Body></soap:Envelope>

注意区别是一个额外的GetViewSummaryForCurrentUserResult元素而不是Views 为了解决这个问题,我必须添加属性

        [return: System.ServiceModel.MessageParameterAttribute(Name = "Views")]
public virtual ViewSummaryList GetViewSummaryForCurrentUser()

....琐碎的解决方案真的,不知道为什么我错过了我