PHP soap服务调用.Net webservice

时间:2014-09-09 11:32:58

标签: c# php .net soap

我想从PHP发送一个在.NET Web服务中定义为datacontract的自定义对象。我试图通过SOAP实现这一目标。这是我的数据合同。

[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; }
 }

这是函数

string SubmitCreditCardInformation(string applicationSessionId,
CreditCardSubmission request)

这是我的PHP代码。

 $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);

以下是我从服务中获得的例外情况: “你调用的对象是空的。”当我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
                )

        )

)

我们从$result2获取会话ID,我们需要使用php soap调用submitcreditcardinformation函数,此处CreditCardNumber只是一个必填字段。

1 个答案:

答案 0 :(得分:0)

    $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);

我得到了解决方案.......感谢所有人......