2012-11-20 61 views
0

我有一個ASMX服務,我遷移到wcf(使用basicHttpBinding),現在我使用的是舊客戶端(使用wsdl.exe生成代理)來打這個服務。我可以看到調用到達服務,服務返回一個非null對象,但是asmx客戶端收到的返回值爲null。從asmx客戶端獲取空值,其目標是從遷移(從asmx到wcf)服務

任何線索爲什麼會發生這種情況,以及如何進一步調試?

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

回答

0

想通了,基本上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元件代替,以便固定次數 它必須添加屬性

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

....瑣碎的解決方案真的,不知道爲什麼我錯過了我