2017-09-28 3 views
-1

C# 서버와 PHP 클라이언트간에 웹 서비스를 사용하려고합니다.비누 오류 '올바른 형식이 아닌 입력 문자열'

인수없이 웹 서비스를 사용할 때 모두 작동합니다!

하지만 함수에 인수를 전달하고자 할 때이 오류가 : SOAPFault의 : 르 형식을 드 라 Chane 디부 연예 동부 표준시 잘못된

내 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 클래스를 추출하는 시험이있다.

아이디어가 있으십니까?

답변

0

저는 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; 
} 
0

감사합니다.

내 문제를 발견했습니다.

나는이 교체했습니다 :

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

이 기준 : 문자열 매개 변수에

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

공간.

관련 문제