WCF服务不返回数据

时间:2015-06-20 02:40:56

标签: c# .net web-services wcf

我有一个简单的WCF项目,它接受XML作为字符串并解析XML以构建搜索对象。然后,搜索对象用于调用调用SQL存储过程的引用项目。然后将结果放入类中,并将类序列化为XML,并由WCF服务作为字符串返回。我能够通过启动它并将其作为另一个项目的Web引用添加来调试WCF服务。在调试模式下,它返回包含14条记录的XML。然后我将WCF服务发布到IIS站点,它返回XML但没有记录。搜索对象存在,因为它只是被解析但引用代码的返回有0条记录。

示例代码如下。所有似乎都执行但是PerformSearch代码没有返回结果。

任何想法??

<?xml version="1.0"?>
<configuration>

<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
  <add binding="basicHttpBinding" scheme="http" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
<directoryBrowse enabled="true"/>
</system.webServer>

</configuration>


public class NCSupplierService : INCSupplierService
{

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
        if (composite == null)
        {
            throw new ArgumentNullException("composite");
        }
        if (composite.BoolValue)
        {
            composite.StringValue += "Suffix";
        }
        return composite;
    }

    public string ProcessOrder(string value)
    {

        try
        {
            XmlDocument oDoc = new XmlDocument();
            oDoc.LoadXml(value);

            string Login = oDoc.SelectSingleNode("NCCriminal/login/user").InnerText.Trim();
            string Password = oDoc.SelectSingleNode("NCCriminal/login/password").InnerText.Trim();

            XmlNode OrderFields = oDoc.SelectSingleNode("NCCriminal/product/Statewide/order");

            int SolutionID = Int32.Parse(oDoc.SelectSingleNode("NCCriminal").Attributes["referenceKey"].Value);
            string FirstName = OrderFields.SelectSingleNode("firstName").InnerText.Trim();
            string MiddleName = OrderFields.SelectSingleNode("middleName").InnerText.Trim();
            string LastName = OrderFields.SelectSingleNode("lastName").InnerText.Trim();
            int dobmonth = Int32.Parse(OrderFields.SelectSingleNode("DOB/month").InnerText.Trim());
            int dobday = Int32.Parse(OrderFields.SelectSingleNode("DOB/day").InnerText.Trim());
            int dobyear = Int32.Parse(OrderFields.SelectSingleNode("DOB/year").InnerText.Trim());
            string SSN = OrderFields.SelectSingleNode("SSN").InnerText.Trim();
            string Gender = OrderFields.SelectSingleNode("Gender").InnerText.Trim();
            string Race = OrderFields.SelectSingleNode("Race").InnerText.Trim();
            string License = OrderFields.SelectSingleNode("DriversLicense/license").InnerText.Trim();
            string LicenseState = OrderFields.SelectSingleNode("DriversLicense/state").InnerText.Trim();
            bool LimitToToDay = oDoc.SelectSingleNode("NCCriminal/product/Statewide/options/LimitToToday").InnerText.Trim() == "NO" ? false : true;


            string ErrorMessage = string.Empty;
            NCSearchTerms SearchTerms = new NCSearchTerms(LastName, FirstName, MiddleName, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, Gender, Race, new DateTime(dobyear, dobmonth, dobday).ToShortDateString(), SSN, new Datastructure.BaseClasses.DriversLicenseType(SolutionID, License, LicenseState));
            NCSearch search = new NCSearch(SearchTerms, SolutionID);
            if(!search.PerformSearch(ref search, SolutionID, LimitToToDay, out ErrorMessage))
                throw new Exception(ErrorMessage);

            if (!string.IsNullOrEmpty(ErrorMessage))
                throw new Exception(ErrorMessage);

            NCCriminalResponse response = new NCCriminalResponse();
            response.SolutionID = SolutionID;
            response.SearchTerms = SearchTerms;
            response.RecordCount = search.SearchResults.SearchResults.Count();
            response.DemographicCaseRecords = search.SearchResults.SearchResults;


            StringBuilder sb = new StringBuilder();
            sb.Append(SerializeXML.SerializeObject(response));
            return sb.ToString();
        }
        catch (Exception Ex)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<?xml version=\"1.0\" encoding=\"utf-16\"?>");
            sb.Append("<NCCriminalResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
            sb.Append("<ProcessingError>");
            sb.Append("<ErrorMessage>");
            sb.Append(Ex.Message);
            sb.Append("</ErrorMessage>");
            sb.Append("</ProcessingError>");
            sb.Append("</NCCriminalResponse>");
            return sb.ToString();
        }
    }

}
//-----------------------------------------------------------------------------------
public class NCCriminalResponse
{
    public int SolutionID;
    public NCSearchTerms SearchTerms;
    public int RecordCount = 0;
    public List<DemographicCase> DemographicCaseRecords = new List<DemographicCase>();
}

1 个答案:

答案 0 :(得分:0)

将[ServiceContract]属性添加到 INCSupplierService 界面,并将[OperationContract]属性添加到其

string ProcessOrder(string value);

属性。

将[DataContract]属性添加到 NCCriminalResponse ,并将[DataMember]属性添加到其公共属性中。