Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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.
PHP
[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
PHP
string SubmitCreditCardInformation(string applicationSessionId,
CreditCardSubmission request)

Here is my PHP code.
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);


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

        )

)

Any help would be greatly appreciated!
Thanks!
Posted
Updated 22-Sep-14 3:11am
v6

1 solution

i'm not a php dev but i think you can serialize it in different ways, i would go for json :

http://php.net/manual/it/function.json-encode.php[^]

but talking about credit card i think that you should use both serialization and something to crypt your data...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900