• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

calling a web service using php

I am trying to call a dotnet webservice using php, and it has just the one method on it. and takes in the following xml string

<?xml version="1.0" encoding="utf-8"?>
<formEvent xmlns:xsi="http://www.w3.org/XMLSchema/Instance">
  <FormID></FormID>
  <ReqID></ReqID>
  <SiteUrl></SiteUrl>
  <FormData>
	<EmailAddress></EmailAddress>
	<EmailAddressConfirm></EmailAddressConfirm>
	<ProductName></ProductName>
	<ModelNumber></ModelNumber>
	<Comments></Comments>
	<FirstName></FirstName>
	<LastName></LastName>
	<Address1></Address1>
	<Address2></Address2>
	<City></City>
	<State></State>
	<Zip></Zip>
	<Phone></Phone>
  </FormData>
</formEvent>

Open in new window


I have the values to be filled in.

The webservice is something like this

 http://ws.mydomain.com/MyContactUs.asmx?op=ProcessContactUs


And I have tried using the following call

function transmitsoap($url, $xmldata) {
	$client = new SoapClient($url); 
	
	
	$result='';
//$result = $client->ProcessContactUs($xmldata); 
$result = $client->ProcessSubscription($xmldata);
	print $result;
	return $result;
	
}

Open in new window


And I am wondering if this is the correct way to call it or is there a better way of doing this?
0
JDEE8297
Asked:
JDEE8297
  • 6
  • 2
2 Solutions
 
Ray PaseurCommented:
What is the ACTUAL URL of the service?  What is the complete, filled-in XML string that you send to the service?  Is there documentation available online?  If so, please give us a link.  What do you get when you print out the $client variable with var_dump()?  What do you get when you print out the $result variable with var_dump()?

If we get that information we can probably help you with this.  Thanks, ~Ray
0
 
JDEE8297Author Commented:
@Ray

I did give you what the call the web service looks like, I can actually put the real web service in here, as it is not something I have permission to do so.

Basically, what I need to know is how you should call a web service in php, if this was in dotnet then it would be done. However, I am working with php and running into some issues that I am not totally familiar with.

This is what is returned:
Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null. Parameter name: s at System.IO.StringReader..ctor(String s) at System.Xml.XmlDocument.LoadXml(String xml) at BissellForm.BissellSubscription.ProcessSubscription(String xmlRequest) --- End of inner exception stack trace
0
 
JDEE8297Author Commented:
function transmitsoap($url, $xmldata) {
	$client = new SoapClient($url); 
	
	
	$result='';
//$result = $client->ProcessContactUs($xmldata); 
$result = $client->ProcessSubscription($xmldata);
	print $result;
	return $result;
	
}

Open in new window


If I call it with the above function, I get the message above.

I have another service call, that is very similar to the one above, and I am getting the same message and this is the code I am using to test it.

function transmitsoap2($url, $xmldata) {
	$client = new SoapClient($url); 
	
	$email = "test@test.com";
	$ishtml = true;
	$action = 1;
	$formid=1;
	$req = "UniqueGuidID";
	$site = "http://www.mydomain.com";
	
	$result='';
	//$result = $client->ProcessContactUs($xmldata); 
	$result = $client->ProcessSubscription(array(
	        "FormId"=>$formid,
			"ReqId"=>$req,
			"SiteUrl"=>$site,
			"FormData"=> array(
			"EmailAddress"=>$email,
			"EmailAddressOld"=>$email,
			"IsHtml"=>$ishtml,
			"Action"=>$action))
			
			
			);
	print $result;
	return $result;
	
}

Open in new window


And I get the same result as I put in my previous comment.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Ray PaseurCommented:
This is a data-dependent error.  Without seeing the actual data and the actual URLs involved, we are just guessing at what might be causing your trouble.  Do you not have any test case you can post here that would enable the experts to see the data and see the error in action?  If you don't I strongly recommend that you set up such a test case and then post the information here so we can work with it.

Until then you might benefit from putting some data visualization techniques in place.  Set error_reporting(E_ALL); and display all of the notices.  Print out all of the objects and strings with var_dump().  That's about all we can tell you until you have test data for us.  HTH, ~Ray
0
 
JDEE8297Author Commented:
hmmmmm....I will see what I can do, atlhough I have to admit, usually when I post the above information that is more than enough for someone to come up with a possible solution. I have posted less information on stuff in the past, but I will see what I can do.

Just very limited in what I can do, since I have no control over the webservice and how that is written and posting in on here is not something I want to do.

If it is a case that no one can at least give me a possible way fo calling web services, or if I am calling it the incorrect way from with in PHP. Then that is a little bit of a downer...but hey, it is what it is...right. :)
0
 
JDEE8297Author Commented:
okay, this is what happens when you deal with a web service, that you didn't write or dont have all the documentation on. You pull what hair you had left out, till there is no more to pull. :)

1. Service was tied down by ip address access.
2. and the requestid is tied down as well

so in both cases, I didn't have the right access to the service.

However, now the message that I am getting back, implies that I am not making the right call with the soapclient method.

$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<formEvent xmlns:xsi=\"http://www.w3.org/XMLSchema/Instance\">
 <FormID>1</FormID>
 <ReqID>8CB767CC-79F2-4AEE-A4EF-6C47CFA0A9C0</ReqID>
 <SiteUrl>http://www.mysite.com</SiteUrl>
 <FormData>
 	<EmailAddress>testuser@test.com</EmailAddress>
	<IsHtml>true</IsHtml>
	<Action>1</Action>
	</FormData>
</formEvent>
";
$success = transmitsoap2($url, $xml);

function transmitsoap2($url, $xmldata) {
	try {
	$client = new SoapClient($url); 

	$email = "test@test.com";
	$ishtml = true;
	$action = 1;
	$formid=1;
	$req = "8CB767CC-79F2-4AEE-A4EF-6C47CFA0A9C0";
	$site = "http://www.mysite.com";
	
	$result='';
	
	$result = $client->ProcessSubscription($xmldata); 
	/*$result = $client->ProcessSubscription(array(
	        "FormId"=>$formid,
			"ReqId"=>$req,
			"SiteUrl"=>$site,
			"FormData"=> array(
			"EmailAddress"=>$email,
			"IsHtml"=>$ishtml,
			"Action"=>$action))); */

	
	

	echo $result;
	print "header = ".htmlspecialchars($client->__getLastRequest());
		
	} catch (Exception $ex) {
		
	
	var_dump($ex->faultcode, $ex->faultstring, $ex->detail);
	}
	
	return $result;	
}

Open in new window


REgardless which way I call this, I get the same message

string 'soap:Server' (length=11)

string 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: s
   at System.IO.StringReader..ctor(String s)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at MyClientForm.MyClientSubscription.ProcessSubscription(String xmlRequest)
   --- End of inner exception stack trace ---' (length=374)

string '' (length=0)

0
 
ezdrtCommented:
Hi,
I can understand your frustration. Here is what I would recommend you to do. For any sort of  webservice client using soap, always try and hit the webservice to see if you can see atleast a list of functions. Here is a simple code you can try:-

Just replace $wsdl with your webservice url or wsdl. Again most webservices you can just embed '?wsdl' and that should be the wsdl location

$wsdl="http://soap.amazon.com/schemas3/AmazonWebServices.wsdl";

$client = new SoapClient($wsdl);
            var_dump($client->__getFunctions());


So begin from here and see if this shows the functions. If this works then you can start experimenting with the functions you want to call like $client->ProcessSubscription();

Here are some other resources to help:
A zend example
http://www.ibm.com/developerworks/webservices/library/x-zsoap/index.html?ca=drs-

http://www.php.net/manual/en/soapclient.getfunctions.php
http://www.soapclient.com/soaptest.html // Excellent debugging tool
Also you can use Altova xmlspy to debug
0
 
JDEE8297Author Commented:
I did eventually end up getting this to work

Couple of things I had to do.
1. Wrap the xml inside an EOS statement.
2. And then call the respective methods like so
$result = $client->ProcessContactUs(array('xmlString'=>$xmldata, 'encoding'=>'utf-16'));

Open in new window


And that returned an array, which I parsed out the result.

So yes, I was frustrated with it, as I was able to connect to the service in php. However, turns out that the service was locked down by ip and the reqid had to be generated for our ip range. A vital piece of information that was not conveyed to us from the client, until I talked to their tech team.

Funny how when you ahve all the information, the thing works. :)
0
 
JDEE8297Author Commented:
As I was able to solve this on my own for the most part.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now