你调用的对象是空的。 PHP

时间:2012-05-29 21:47:37

标签: php .net web-services soap

我知道这个“对象引用未设置为对象的实例”已经出现了很多,但我所看到的所有答案似乎并没有帮助我。

这是我的WSDL:https://app.20-20insights.com/testepos/servicetrx.svc?wsdl

我正在尝试调用BeginTrx()函数,但是我收到了错误。

非常感谢任何建议或帮助。

谢谢, 马丁。

设置TrxIdentifier对象

$trxIdentifier = new TrxIdentifier;

$trxIdentifier->ClientId = 9372490002639296;
$trxIdentifier->DeviceId = "123";
$trxIdentifier->OpId = "123";
$trxIdentifier->PosDescription = "123";
$trxIdentifier->PosId = "123";
$trxIdentifier->PosTxnId = "123";
$trxIdentifier->SiteId = "12312";
$trxIdentifier->Token = "3";
$trxIdentifier->TrxdateTime = new DateTime;

执行通话......

$client = new SoapClient($wsdl,  array('trace'=>true,
'exceptions'=>true,
'classmap'=>array('TrxIdentifier'=>"TrxIdentifier", 'MemberInfo'=>"MemberInfo", 'Response'=>"Response", 'MemberDetail'=>"MemberDetail")));

$response = $client->BeginTrx($trxIdentifier );

错误:

Object reference not set to an instance of an object.
a:InternalServiceFaultObject reference not set to an instance of an object.Object reference not set to an instance of an object. at CatalystSpsTrx.Contracts.Service.ServiceTrx.BeginTrx(MemberInfo& mem, TrxIdentifier conTrx) in C:\Projects\2010\CatTrxServices\CatalystSpsTrx.Contracts\Service\ServiceTrx.cs:line 38
 at _dynamic_CatalystSpsTrx.Contracts.Service.ServiceTrx.BeginTrx(Object , Object[] )
 at Spring.Reflection.Dynamic.SafeMethod.Invoke(Object target, Object[] arguments)
 at Spring.Aop.Framework.DynamicMethodInvocation.InvokeJoinpoint()
 at Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor.Invoke(IMethodInvocation invocation)
 at Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptor.Invoke(IMethodInvocation invocation)
 at CompositionAopProxy_d0e73463863e4ccd9c2db0a96530bd0d.BeginTrx(MemberInfo& mem, TrxIdentifier conTrx)
 at ServiceTrx.BeginTrx(MemberInfo& mem, TrxIdentifier conTrx)
 at SyncInvokeBeginTrx(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)System.NullReferenceException

1 个答案:

答案 0 :(得分:3)

发生该错误是因为输入结构错误。您的WSDL声明必须以这种方式调用它:

$response = $client->BeginTrx(array('trx' => $trxIdentifier));

看一下WSDL,这是服务BeginTrx的根输入定义:

<wsdl:message name="IServiceTrx_BeginTrx_InputMessage">
    <wsdl:part name="parameters" element="tns:BeginTrx"/>
</wsdl:message>

如您所见,输入的类型为BeginTrx。如果您遵循WSDL,您会发现它被定义为:

<xs:element name="BeginTrx">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="trx" nillable="true" type="tns:TrxIdentifier"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

因此,您可以看到BeginTrx的参数名称为trx,值为TrxIdentifier

再次遵循WSDL,TrxIdentifier定义为:

<xs:complexType name="TrxIdentifier">
    <xs:sequence>
    <xs:element minOccurs="0" name="ClientId" type="xs:int"/>
    <xs:element minOccurs="0" name="DeviceId" nillable="true" type="xs:string"/>
    .................
    </xs:sequence>
</xs:complexType>