Solved

calling a web service using php

Posted on 2011-02-26
9
411 Views
Last Modified: 2012-05-11
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
Comment
Question by:JDEE8297
  • 6
  • 2
9 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34991502
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
 

Author Comment

by:JDEE8297
ID: 34991577
@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
 

Author Comment

by:JDEE8297
ID: 34991594
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34991772
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:JDEE8297
ID: 34993100
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
 

Author Comment

by:JDEE8297
ID: 34999609
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
 

Accepted Solution

by:
ezdrt earned 250 total points
ID: 35002134
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
 

Assisted Solution

by:JDEE8297
JDEE8297 earned 0 total points
ID: 35017773
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
 

Author Closing Comment

by:JDEE8297
ID: 35067701
As I was able to solve this on my own for the most part.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now