问题描述
我的问题是我有一个.asmx webservice(.net webservice),其中一个方法名称WriteLogInDB接受参数,即.net类的对象。现在我想通过从php传递一个对象来调用WriteLogInDB方法。我如何调用该方法以及如何从php传递对象。
**我的尝试**
使用soap客户端调用我通过传递带有一些数据的对象(PHP类对象)来调用该方法。但它到达webservice它变为空,我得到了webservice WriteLogInDB方法的响应(对象不能为null。在WriteLogInDB中它首先检查对象天气它是空的,如果它是空的,它返回msg对象不能为空。)。
但我没有传递一个空对象。
**我的代码**
$ ini = ini_set(soap.wsdl_cache_enabled, 0);
$ url =http://log.cocoonit.in/writelogsindbservice.asmx?WSDL;
//创建soap客户端
$ client = new SoapClient($ url,array(trace=> 1,exception=> 0));
$ objLogParameter = new LogParameters(); //我的php类
$ objLogParameter-> strLogMessage = $ message。 。$ extendedMessage;
$ objLogParameter-> strStackTrace = $ preStackTrace;
$ objLogParameter-> strUser =Osmosys;
$ objLogParameter-> strCustomer =ws;
$ objLogParameter-> strPageOrModuleName =调用ws;
$ objLogParameter-> strApplication =OsmTest;
$ objLogParameter-> strSubscription =test2;
$ objLogParameter-> EnumSeverity =错误;
$ objLogParameter-> EnumLogType =ErrorTest;
//通过传递对象来调用webservice方法
$ res = $ client-> WriteLogInDB($ objLogParameter);
//在$ res中,我在该对象中得到了一个stdClass对象(WriteLogInDB =>对象),$ StausCode = 0,$ StatusMessage = object不能为null。 />
我尝试过另一种方式,比如
$ objLogParameter = new stdClass();
$ objLogParameter-> strLogMessage = $ message;
$ objLogParameter-> strStackTrace = $ preStackTrace;
$ objLogParameter-> strUser =Osmosys;
$ objLogParameter-> strCustomer =ws;
$ objLogParameter-> strPageOrModuleName = 调用ws;
$ objLogParameter-> strApplication =OsmTest;
$ objLogParameter-> strSubscription =test2;
$ objLogParameter-> EnumSeverity =错误;
$ objLogParameter-> EnumL ogType =ErrorTest;
$ res = $ client-> WriteLogInDB($ objLogParameter);
还有一种方法我尝试传递一个对象之前我编码(json_encode)对象,然后调用方法。
即使我得到相同的结果..
What my problem is I have a .asmx webservice(.net webservice) in that one method name WriteLogInDB which accepts argument i.e object of a .net class. Now i want to call that WriteLogInDB method by passing an object from php. How can i call that method and how can i pass the object from php.
**My Attempts**
By using soap client call i call that method by passing an object with some data (PHP class object).But it reaches to webservice it became empty and i got a response from webservice WriteLogInDB method (object can't be null. In WriteLogInDB it first checks the object weather it is empty or not if it is empty it returns msg object can't be null. ) .
But i am not passing an empty object.
**My code**
$ini = ini_set("soap.wsdl_cache_enabled","0");
$url = "http://log.cocoonit.in/writelogsindbservice.asmx?WSDL";
//creating soap client
$client = new SoapClient($url, array("trace" => 1 , "exception" => 0));
$objLogParameter = new LogParameters(); // my php class
$objLogParameter->strLogMessage = $message." ".$extendedMessage;
$objLogParameter->strStackTrace = $preStackTrace;
$objLogParameter->strUser = "Osmosys";
$objLogParameter->strCustomer = "ws";
$objLogParameter->strPageOrModuleName = "calling ws";
$objLogParameter->strApplication = "OsmTest";
$objLogParameter->strSubscription = "test2";
$objLogParameter->EnumSeverity = "Error";
$objLogParameter->EnumLogType = "ErrorTest";
//calling webservice method by passing an object
$res = $client->WriteLogInDB($objLogParameter);
//In $res i got an stdClass obect (WriteLogInDB => object) in that object ,$StausCode = 0, $StatusMessage = object can not be null.
I tried in another way also like
$objLogParameter = new stdClass();
$objLogParameter->strLogMessage = $message;
$objLogParameter->strStackTrace = $preStackTrace;
$objLogParameter->strUser = "Osmosys";
$objLogParameter->strCustomer = "ws";
$objLogParameter->strPageOrModuleName = "calling ws";
$objLogParameter->strApplication = "OsmTest";
$objLogParameter->strSubscription = "test2";
$objLogParameter->EnumSeverity = "Error";
$objLogParameter->EnumLogType = "ErrorTest";
$res = $client->WriteLogInDB($objLogParameter);
One more way also i tried like before passing an object i encode (json_encode ) the object and then call the method.
Even though i got same result..
推荐答案
这篇关于如何从Php肥皂客户端将对象作为参数传递给.Asmx Web服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!