Pregunta

This is an interesting problem, and I will do my best to explain. If you have any questions, please ask.

I have written a WCF service that is suppose to communicate with a JAVA client. This service was created via contract first from a WSDL. Now, according to the WCF test client everything works, even testing on a PHP client works as well. But when it comes to the Java client, the request messages and subsequent response messages fail to return: I get a null object SOAP fault. Here is were I think the problem lies:

According to the XSD and WSDL, I have a DateTime value that I am suppose to take in. This dateTime value from the client is of form: 2012-01-01T12:00:00.00Z. Unfortunately, this input is not valid with the built in .NET datetime. So, to get around this, I changed my code to take in a string datatype, convert that string to a Datetime to send it to the database, get a response from the database in that dateTime and convert it back to a string for the response to return a value that is like the one that was inputted.

I built a logger to check to see if the messages were being sent to and from my wcf service. From that, I have identified that messages from the client were not being received. My only guess is that it is because of the datetime issue.

Is there a way to take in a dateTime datatype in the format: 2012-01-01T12:00:00.000Z? If i can, then that will mean that the request will match my datatype and maybe it will work.

Here is some code:

    public partial class findSeatsRequest
{

    [MessageBodyMemberAttribute(Namespace="http://soa.cs.uwf.edu/airlineData", Order=0, Name="departAirport")]
    public string DepartAirport;

    [MessageBodyMemberAttribute(Namespace="http://soa.cs.uwf.edu/airlineData", Order=1, Name="arriveAirport")]
    public string ArriveAirport;

    [MessageBodyMemberAttribute(Namespace="http://soa.cs.uwf.edu/airlineMessage", Order=2, Name="earliestDepartTime")]
    public string EarliestDepartTime;

    [MessageBodyMemberAttribute(Namespace="http://soa.cs.uwf.edu/airlineMessage", Order=3, Name="latestDepartTime")]
    public string LatestDepartTime;

    [MessageBodyMemberAttribute(Namespace="http://soa.cs.uwf.edu/airlineMessage", Order=4, Name="minimumSeatsAvailable")]
    public int MinimumSeatsAvailable;

    [MessageBodyMemberAttribute(Namespace="http://soa.cs.uwf.edu/airlineMessage", Order=5, Name="maximumFlightsToReturn")]
    public int MaximumFlightsToReturn;

    public findSeatsRequest()
    {
    }

    public findSeatsRequest(string departAirport, string arriveAirport, string earliestDepartTime, string latestDepartTime, int minimumSeatsAvailable, int maximumFlightsToReturn)
    {
        this.DepartAirport = departAirport;
        this.ArriveAirport = arriveAirport;
        this.EarliestDepartTime = earliestDepartTime;
        this.LatestDepartTime = latestDepartTime;
        this.MinimumSeatsAvailable = minimumSeatsAvailable;
        this.MaximumFlightsToReturn = maximumFlightsToReturn;
    }
}


    public partial class findSeatsResponse
{

    [MessageBodyMemberAttribute(Namespace="http://soa.cs.uwf.edu/airlineData", Order=0, Name="flight")]
    [XmlElementAttribute("flight")]
    public System.Collections.Generic.List<flightType> Flight;

    public findSeatsResponse()
    {
    }

    public findSeatsResponse(System.Collections.Generic.List<flightType> flight)
    {
        this.Flight = flight;
    }
}

        public virtual findSeatsResponse findSeats(findSeatsRequest request)
    {
        string departAirport = request.DepartAirport;
        string arriveAirport = request.ArriveAirport;
        string earliestDepartTime = request.EarliestDepartTime;
        string latestDepartTime = request.LatestDepartTime;
        int minimumSeatsAvailable = request.MinimumSeatsAvailable;
        int maximumFlightsToReturn = request.MaximumFlightsToReturn;
        SqlCommand cmd = null;
        DataSet ds = new DataSet();
        List<flightType> flight = new List<flightType>();
        EventLogger log = new EventLogger();

        findSeatsRequest inValue = new findSeatsRequest();
        inValue.DepartAirport = departAirport;
        inValue.ArriveAirport = arriveAirport;
        inValue.EarliestDepartTime = earliestDepartTime;
        inValue.LatestDepartTime = latestDepartTime;
        inValue.MinimumSeatsAvailable = minimumSeatsAvailable;
        inValue.MaximumFlightsToReturn = maximumFlightsToReturn;

        string latestT = inValue.LatestDepartTime.Replace("T", " ");
        string latestZ = latestT.Replace("Z", "");
        DateTime _latestDepartTime = DateTime.ParseExact(latestZ, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);

        string earliestT = inValue.EarliestDepartTime.Replace("T", " ");
        string earliestZ = earliestT.Replace("Z", "");
        DateTime _earliestDepartTime = DateTime.ParseExact(earliestZ, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);

        log.WriteToDataBase(DateTime.Now, "FindSeats", 1, "This is the request: " + inValue);


        //Check Maximum Flights
        if (inValue.MaximumFlightsToReturn > 100 | inValue.MaximumFlightsToReturn < 0)
        {
            throw new FaultException(
                "You cannot select more than 100 flights to return, or the maximum flights to return is negative.",
                new FaultCode("OutOfRange"));
        }

        // Check Minimum Seats Available.
        if (inValue.MinimumSeatsAvailable < 0)
        {
            throw new FaultException(
                "You minimum seats available cannot be negative.",
                new FaultCode("OutOfRange"));
        }

        // Check for valid Departure Airport
        if (departAirport != null && departAirport != "ANY")
        {
            try
            {
                string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
                SqlConnection conn = new SqlConnection(strConn);

                conn.Open();

                string check = "SELECT DepartAirport FROM Flight WHERE DepartAirport='" + departAirport + "'";
                cmd = new SqlCommand(check, conn);
                cmd.CommandText = check;
                SqlDataReader depAirport;
                depAirport = cmd.ExecuteReader();

                if (depAirport.HasRows == false)
                {
                    throw new FaultException(
                        "Invalid Airport code used.",
                        new FaultCode("Invalid Text Entry"));
                }
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        // Check for valid Arrival Airport
        if (arriveAirport != null && arriveAirport != "ANY")
        {
            try
            {
                string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
                SqlConnection conn = new SqlConnection(strConn);

                conn.Open();

                string check = "SELECT ArriveAirport FROM Flight WHERE ArriveAirport='" + arriveAirport + "'";
                cmd = new SqlCommand(check, conn);
                cmd.CommandText = check;
                SqlDataReader arrAirport;
                arrAirport = cmd.ExecuteReader();

                if (arrAirport.HasRows == false)
                {
                    throw new FaultException(
                        "Invalid Airport code used.",
                        new FaultCode("Invalid Text Entry"));
                }
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }
        }

        try
        {
            string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            SqlConnection conn = new SqlConnection(strConn);

            conn.Open();

            cmd = new SqlCommand("usp_NewFindSeats", conn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@DepartureAirport", inValue.DepartAirport));
            cmd.Parameters.Add(new SqlParameter("@ArrivalAirport", inValue.ArriveAirport));
            cmd.Parameters.Add(new SqlParameter("@EarliestDepTime", _earliestDepartTime));
            cmd.Parameters.Add(new SqlParameter("@LatestDepTime", _latestDepartTime));
            cmd.Parameters.Add(new SqlParameter("@minSeatsAvailable", inValue.MinimumSeatsAvailable));
            cmd.Parameters.Add(new SqlParameter("@maxFlightsRequested", inValue.MaximumFlightsToReturn));

            using (SqlDataReader sqlReader = cmd.ExecuteReader())
            {
                while (sqlReader.Read())
                {
                    flightType Flight = new flightType();

                    Flight.FlightId = sqlReader.GetString(0);
                    Flight.DepartAirport = sqlReader.GetString(1);
                    Flight.ArriveAirport = sqlReader.GetString(2);
                    Flight.DepartTime = sqlReader.GetDateTime(3).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
                    Flight.ArriveTime = sqlReader.GetDateTime(4).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
                    Flight.FlightSeatsAvailable = sqlReader.GetInt32(5);
                    Flight.FlightSeatPriceUSD = sqlReader.GetDouble(6);

                    flight.Add(Flight);
                }
            }
¿Fue útil?

Solución

For this particular problem, the issue wasn't anything I thought it was in the beginning. Firstly, had to use WrapperNames in my C# code's request operations and the names I used were incorrect.

Secondly, I needed to specify SOAP Body encoding which I had to do within my Interface layer.

 [XmlSerializerFormatAttribute(SupportFaults=true, Style=OperationFormatStyle.Document ,Use=OperationFormatUse.Literal)]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top