【问题标题】:soap fault 'Input String Not In Correct Format'肥皂故障“输入字符串格式不正确”
【发布时间】:2017-09-28 20:48:10
【问题描述】:

我尝试在 c# 服务器和 php 客户端之间使用 web 服务。

当我使用不带参数的网络服务时,一切正常!

但是当我想将参数传递给函数时,我遇到了这个错误: SoapFault : Le format de la chaîne d'entrée est 不正确

我的 wsdl 文件: https://pastebin.com/ti805zkW

我的php代码:

public function previewAction(Request $req)
{
    $client = new \SoapClient("http://localhost:1664/WebReport/Service/?wsdl");
    $preview = $client->Preview(array('id' => 1, 'choice' => 2, 'userDate' => 'test'));
    return new JsonResponse($preview);
}

我的 c# Iservice 代码:

using System.Collections.Generic;
using System.ServiceModel;

namespace WebReport
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        bool Reload();

        [OperationContract]
        bool Treatment();

        [OperationContract]
        Dictionary<string, float> Preview(int id, int choice, string userDate);
    }
}

我的 c# 服务代码:

using System;
using System.Collections.Generic;

namespace WebReport
{
    public class Service : IService
    {
        public bool Reload()
        {
            //Application.GetInstance().ReloadConfig();
            return true;
        }

        public bool Treatment()
        {
            //DataPoints.Treatment.GetInstance().run();
            return true;
        }

        public Dictionary<string, float> Preview(int id, int choice, string userDate)
        {
            Console.WriteLine("{ 0}.{ 1}.{ 2}", id, choice, userDate);
            Dictionary<string, float> test = new Dictionary<string, float>();
            test.Add("2017-05-04 10:10:10", 100000);
            test.Add("2017-05-05 10:10:10", 100001);
            return test;
        }
    }
}

我已经测试使用 wsdl2phpgenerator 从 wsdl 文件中提取 php 类,但同样的错误。

有什么想法吗?

【问题讨论】:

    标签: c# php web-services soap wsdl


    【解决方案1】:

    我不是 PHP 开发人员,但在使用 PHP 测试我自己的 API 时,我接受控制器中的对象,而不是每个数组项的参数。

    因此,创建一个具有与数组匹配的属性的类,并将其作为控制器的一个参数。

    public class PreviewDTO
    {
        public int id { get; set; }
        public int choice { get; set; }
        public string userDate { get; set; }
    }
    

    还有控制器:

    public Dictionary<string, float> Preview(PreviewDTO prev)
    {
        Console.WriteLine("{ 0}.{ 1}.{ 2}", prev.id, prev.choice, prev.userDate);
        Dictionary<string, float> test = new Dictionary<string, float>();
        test.Add("2017-05-04 10:10:10", 100000);
        test.Add("2017-05-05 10:10:10", 100001);
        return test;
    }
    

    【讨论】:

      【解决方案2】:

      感谢您的回答。

      我发现了我的问题。

      我已经替换了这个:

      Console.WriteLine("{ 0}.{ 1}.{ 2}", id, choice, userDate);
      

      通过这个:

      Console.WriteLine("{0}.{1}.{2}", id, choice, userDate);
      

      字符串参数中的空格。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-23
        相关资源
        最近更新 更多