【问题标题】:Getting null values from asmx client which targets a migrated (from asmx to wcf) service从针对迁移(从 asmx 到 wcf)服务的 asmx 客户端获取空值
【发布时间】:2012-11-20 08:49:59
【问题描述】:

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

任何线索为什么会发生这种情况以及如何进一步调试?

  // 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]));
        }

【问题讨论】:

    标签: wcf asmx


    【解决方案1】:

    想通了,基本上soap响应生成错误

    <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()
    

    .... 真的是微不足道的解决方案,不知道为什么我错过了我

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 2014-01-20
      • 1970-01-01
      相关资源
      最近更新 更多