C# soap故障';输入字符串格式不正确';
我尝试在c#服务器和php客户端之间使用web服务 当我使用不带参数的web服务时,一切正常 但当我想将参数传递给函数时,我有一个错误: SoapFault:Le format de la chaîne d'entrée est不正确 我的wsdl文件: 我的php代码:C# soap故障';输入字符串格式不正确';,c#,php,web-services,soap,wsdl,C#,Php,Web Services,Soap,Wsdl,我尝试在c#服务器和php客户端之间使用web服务 当我使用不带参数的web服务时,一切正常 但当我想将参数传递给函数时,我有一个错误: SoapFault:Le format de la chaîne d'entrée est不正确 我的wsdl文件: 我的php代码: public function previewAction(Request $req) { $client = new \SoapClient("http://localhost:1664/WebReport/Ser
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#iSeries设备代码:
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);
}
}
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;
}
}
}
使用System.Collections.Generic;
使用System.ServiceModel;
命名空间WebReport
{
[服务合同]
公共接口设备
{
[经营合同]
bool-Reload();
[经营合同]
布尔处理();
[经营合同]
字典预览(int-id、int-choice、字符串userDate);
}
}
我的c#服务代码:
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);
}
}
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;
}
}
}
使用系统;
使用System.Collections.Generic;
命名空间WebReport
{
公共课服务:IService
{
公共bool Reload()
{
//Application.GetInstance().ReloadConfig();
返回true;
}
公共废物处理()
{
//DataPoints.Treatment.GetInstance().run();
返回true;
}
公共字典预览(int-id、int-choice、字符串userDate)
{
WriteLine(“{0}.{1}.{2}”,id,choice,userDate);
字典测试=新字典();
试验添加(“2017-05-04 10:10:10”,100000);
试验添加(“2017-05-05 10:10:10”,100001);
回归试验;
}
}
}
我用WSDL2HPGenerator从wsdl文件中提取php类,但有相同的错误
有什么想法吗?我不是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;
}
公共词典预览(PreviewTo prev)
{
WriteLine(“{0}.{1}.{2}”,prev.id,prev.choice,prev.userDate);
字典测试=新字典();
试验添加(“2017-05-04 10:10:10”,100000);
试验添加(“2017-05-05 10:10:10”,100001);
回归试验;
}
谢谢您的回答
我发现了我的问题
我已经替换了这个:
Console.WriteLine("{ 0}.{ 1}.{ 2}", id, choice, userDate);
据此:
Console.WriteLine("{0}.{1}.{2}", id, choice, userDate);
字符串参数中的空格