0

I would like to use php to call a c# webmethod but it's unsuccessful - why?

    try {

    $client = new SoapClient($VerifyUser);

    $params = array( 
        'Merchant_id'  => $tbl_result['tbl_merchant']['data'][0]->Merchant_id, 
        'Merchant_code' => $tbl_result['tbl_merchant']['data'][0]->Merchant_code
    );

    $response = $client->VerifyUser(
        array(
            'Merchant_id'=>$tbl_result['tbl_merchant']['data'][0]->Merchant_id
        )
    )->VerifyUserResult;
} catch (Exception $e) {
    print_r($e->getMessage());
}

////////////// C#

    [WebMethod]
    public static string VerifyUser(string Merchant_id)
    {
        return "";
    }

There is an error as below:

Function ("VerifyUser") is not a valid method for this service

Now i change to below:

$clsUser = array( 'xxx' => 'xxx' ); 
$urlWebService = "xxx.asmx?WSDL"; 
$response = WebSoapClient("VerifyUser", $urlWebService, $clsUser); 


function WebSoapClient($function ,$url, $data = array() ) { 
    $response = null; 
    try { 
        $client = new SoapClient($url); 
        $response = $client->__soapCall( $function, $data ); 
    } catch (Exception $e) { 
        ErrorLog("WebSoapClient->". $function . " - " . $e->getMessage()); 
    } 
    return $response; 
} 


/C# 
[WebMethod] 
public string VerifyUser(clsUser clsUser) { 
    //xxx...
} 

but in C# param is null...

3
  • Is the webmethod in an asmx service or aspx, or what? Are you sure it's definitely a SOAP interface? Is there a WSDL? Commented Nov 17, 2021 at 9:54
  • Yes it is WSDL. Now i change to below: $clsUser = array( 'xxx' => 'xxx' ); $urlWebService = "xxx.asmx?WSDL"; $response = WebSoapClient("VerifyUser", $urlWebService, $clsUser); function WebSoapClient($function ,$url, $data = array() ) { $response = null; try { $client = new SoapClient($url); $response = $client->__soapCall( $function, $data ); } catch (Exception $e) { ErrorLog("WebSoapClient->". $function . " - " . $e->getMessage()); } return $response; } /C# [WebMethod] public string VerifyUser(clsUser clsUser) { } but in C# param is null... Commented Nov 18, 2021 at 10:39
  • Ok. So, what was the result of that change? P.s. if you have new code to share, please edit your question - do not put code in these comments where you cannot easily format it, thanks. The "edit" button is at the end of your question just below the little blue tags Commented Nov 18, 2021 at 10:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.