0

我无法让我的 PHP 应用程序正确地将参数传递给我的 .NET 4.0 WCF 服务。这是服务代码:

[OperationBehavior(ReleaseInstanceMode = ReleaseInstanceMode.AfterCall)]
int ICatalogService.CalculatePercentComplete(CoursePercentParam cpp)
{
     string courseID = cpp.Course;
     int mediaIndex = cpp.MediaIndex;
     double position = cpp.Position;

     return ((ICatalogService)this).CalculateCoursePercentComplete(courseID, mediaIndex, position);
}

和 CoursePercentParam 类:

[DataContract(Namespace = "Somenamespace.Core.1.0")]
public class CoursePercentParam
{
    string course;
    int mediaindex;
    double position;
    public CoursePercentParam()
    {
    }
    public CoursePercentParam(CoursePercentParam cpp)
        : this()
    {
        this.Course = cpp.Course;
        this.MediaIndex = cpp.MediaIndex;
        this.Position = cpp.Position;
    }

    public string Course { get { return this.course; } set { this.course = value; } }
    public int MediaIndex { get { return this.mediaindex; } set { this.mediaindex = value; } }
    public double Position { get { return this.position; } set { this.position = value; } }
}

请注意,代码中还有其他几个地方我可以毫无问题地调用此服务。- 按预期工作。Web 应用程序和 WCF 服务之间的通信正在工作。仅此一次调用无法正确获取参数。

以下是调用它的 PHP 代码:

$getPercentComplete_obj->cpp = array('Course' => $showcurrentcourse->CourseIdentifier, 'MediaIndex' => $mediaIndex, 'Position' => $position);
$getPercentComplete_res = $courseService->CalculatePercentComplete($getPercentComplete_obj);
$percentComplete = $getPercentComplete_res->CalculatePercentCompleteResult;

以下是 PHP 应用程序的打印参数:

stdClass Object
(
    [cpp] => Array
        (
            [Course] => BI-0310
            [MediaIndex] => 5
            [Position] => 1203.234
        )

)
stdClass Object
(
    [CalculatePercentCompleteResult] => -1
)

正如您在此处看到的,在 PHP 应用程序中存在参数数据。看了好几个小时,似乎找不到问题。

仅供参考:以下是上面此方法调用的方法。我也尝试过使用$param_obj->courseID = $courseID单个参数,字符串参数总是为空。这就是为什么我创建了采用“CoursePercentParam”类的方法。无论如何,这是代码:

    [OperationBehavior(ReleaseInstanceMode = ReleaseInstanceMode.AfterCall)]
    int ICatalogService.CalculateCoursePercentComplete(string courseID, int mediaIndex, double position)
    {
        Trace.TraceInformation("courseID=>'{0}', mediaIndex=>'{1}', position=>'{2}'",
            courseID, mediaIndex, position);

        Course course = ((ICatalogService)this).GetCourse(courseID);
        if (null == course)
            return -1;

        double current = ((ICatalogService)this).CalculateCourseProgress(courseID, mediaIndex, position);
        double total = ((ICatalogService)this).GetCourseLength(course);

        int percent = (int)((current / total) * 100);
        Trace.TraceInformation("Percent Complete: {0}", percent);
        return percent;
    }

我会很感激我能得到的任何帮助。

谢谢你,吉姆

4

0 回答 0