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 サービス間の通信は機能しています。この 1 回の呼び出しだけでは、パラメーターが正しく取得されません。

以下は、それを呼び出す 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