0

我有一个迁移到 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]));
        }
4

1 回答 1

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

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

于 2012-11-21T06:26:45.470 回答