dq8081 2014-09-09 11:32
浏览 114

PHP soap服务调用.Net webservice

I want to send a custom object thats defined as a datacontract in my .NET web service from PHP. I'm attempting to accomplish this via SOAP. Here is my datacontract.

[DataContract(Namespace = "www.xxxxx.com/data/v1")]
  public class CreditCardSubmission
 {
   [DataMember]
   public string CreditCardNumber { get; set; }
   [DataMember]
   public int ExpireMonth { get; set; }
   [DataMember]
   public int ExpireYear { get; set; }
   [DataMember] 
   public string CardNickname { get; set; }
   [DataMember]
   public string CardholderName { get; set; }
   [DataMember]
   public string Address { get; set; }
   [DataMember]
   public string City { get; set; }
   [DataMember]
   public string State { get; set; }
   [DataMember]
   public string PostalCode { get; set; }
   [DataMember]
   public string Country { get; set; }
 }

Here is the function

string SubmitCreditCardInformation(string applicationSessionId,
CreditCardSubmission request)

Here is my PHP code.

 $result2 = $client->call("UserLogin", array(
    "AppSessionID" =>$result['StartAppSessionResult']'SessionID'],
                                                    "LoginName" => "xxxxxxx",
                                                    "Password" => "xxxxxxxx",
                                                    "RetrieveSecurityGroups" => FALSE));

$client_cc = new nusoap_client('https://abc.com/abc.svc?wsdl', 'WSDL');
$obj = new stdClass();
$obj->CreditCardNumber = "4518169332998699";
$obj->ExpireMonth = 05;
$obj->ExpireYear = 2025;
$obj->CardNickname = "Test Card";
$obj->CardholderName = "John Doe";
$obj->Address = "123 Main Street";
$obj->City = "Anywhere";
$obj->State = "CA";
$obj->PostalCode = "92000";
$obj->Country ="Sandeep";
$parameter= array("CreditCardSubmission" => $obj);

$result3 = $client_cc->call(
    'SubmitCreditCardInformation', array($result['UserLoginResult']['SessionID']), $parameter);

Below is the exception I'm getting from the service: "Object reference not set to an instance of an object." when i print_r($result3);

Array
(
    [faultcode] => a:InternalServiceFault
    [faultstring] => Array
        (
            [!xml:lang] => en-US
            [!] => Object reference not set to an instance of an object.
        )

    [detail] => Array
        (
            [ExceptionDetail] => Array
                (
                    [HelpLink] => 
                    [InnerException] => 
                    [Message] => Object reference not set to an instance of an object.
                    [StackTrace] =>    at Viad.Services.Public.GES.v1.OrderService.SubmitCreditCardInformation(String applicationSessionId, CreditCardSubmission request) in c:\SVN\Viad.GES.Services\Branches\PublicServices_v1\Viad.Services.Public.GES\v1\OrderService.svc.cs:line 1246
   at SyncInvokeSubmitCreditCardInformation(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
                    [Type] => System.NullReferenceException
                )

        )

)

We are getting the session id from the $result2, We need to call the submitcreditcardinformation function using php soap, here CreditCardNumber is only one mandatory field.

  • 写回答

1条回答 默认 最新

  • dongsi7759 2014-09-25 10:31
    关注
        $Address = 'test';
        $CardNickname = 'test';
        $CardholderName = 'test';
        $City = 'test';
        $Country = 'test';  
        $CreditCardNumber = '4532586989865974';
        $ExpireMonth = 5;
        $ExpireYear = 2015;     
        $PostalCode = 'test';
        $State = 'test';
    $serviceurl2 = 'https://abc.com/orderService.svc?wsdl';//Soap url
    $namespacemethod = 'www.xxx.com/v1/clssname/SubmitCreditCardInformation';   
    
            $client_card = new nusoap_client($serviceurl2, TRUE);
            $client_card->soap_defencoding = 'UTF-8';   
                $client->useHTTPPersistentConnection(); 
                $xml_str ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="www.xxx.com/v1" xmlns:v11="www.xxx.com/data/v1">
               <soapenv:Header/>
               <soapenv:Body>
                  <v1:SubmitCreditCardInformation>
                     <!--Optional:-->
                     <v1:applicationSessionId>'.$result2['UserLoginResult']['SessionID'].'</v1:applicationSessionId>
                     <!--Optional:-->
                     <v1:request>
                        <!--Optional:-->
                        <v11:Address>'.$Address.'</v11:Address>
                        <!--Optional:-->
                        <v11:CardNickname>'.$CardNickname.'</v11:CardNickname>
                        <!--Optional:-->
                        <v11:CardholderName>'.$CardholderName.'</v11:CardholderName>
                        <!--Optional:-->
                        <v11:City>'.$City.'</v11:City>
                        <!--Optional:-->
                        <v11:Country>'.$Country.'</v11:Country>
                        <!--Optional:-->
                        <v11:CreditCardNumber>'.$CreditCardNumber.'</v11:CreditCardNumber>
                        <!--Optional:-->
                        <v11:ExpireMonth>'.$ExpireMonth.'</v11:ExpireMonth>
                        <!--Optional:-->
                        <v11:ExpireYear>'.$ExpireYear.'</v11:ExpireYear>
                        <!--Optional:-->
                        <v11:PostalCode>'.$PostalCode.'</v11:PostalCode>
                        <!--Optional:-->
                        <v11:State>'.$State.'</v11:State>
                     </v1:request>
                  </v1:SubmitCreditCardInformation>
               </soapenv:Body>
            </soapenv:Envelope>';
            $credicard_token = $client_card->send($xml_str, $namespacemethod);
    Print_r($credicard_token);
    

    I got solution.......Thx to all...

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c