Answered by:
Use External WebServices in CRM

Question
-
How can we use external webservice in CRM? I want to use webservice in CRM Forms.Tuesday, June 2, 2009 4:15 AM
Answers
-
You can use javascript to use external webservice in crm.
here is one link to use webservice through javascript
"http://blog.customereffective.com/blog/2008/02/calling-the-crm.html"
Mahain- Proposed as answer by Nishant RanaMVP Tuesday, June 2, 2009 4:55 AM
- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 4:44 AMModerator -
Here is the code to use external webservice in crm using JS
var soapRequest="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap="+
"\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<soap:Body>"+
"<webmethodname xmlns=\'http://tempuri.org/\'>"+
"<ParameterName>"+parameter+</ParameterName>"+
"</webmethodname>"+
" </soap:Body>"+
"</soap:Envelope>";var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("post","your externalweb service URL", false);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlHttp.setRequestHeader("Content-Length", soapRequest.length);
xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/webmethodname");
xmlHttp.send(soapRequest);var responseXML=xmlHttp.responseXML;
alert(responseXML);
Hope it will help
Mahain- Proposed as answer by Andrii ButenkoMVP, Moderator Tuesday, June 2, 2009 5:23 AM
- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 5:08 AMModerator -
Hi.
You can look article from SDK as sample of External Web Services call.
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Proposed as answer by Andrii ButenkoMVP, Moderator Tuesday, June 2, 2009 5:23 AM
- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 5:23 AMModerator -
Hi.
Look this thread .
I hope this will help you.
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 7:53 AMModerator -
var soapRequest="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap="+
"\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<soap:Body>"+
"<HelloWorld xmlns=\'http://tempuri.org/\'>"+
"<Msg>'Hello tusman'</Msg>"+
"</HelloWorld>"+
" </soap:Body>"+
"</soap:Envelope>";var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("post","your webservice url", false);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlHttp.setRequestHeader("Content-Length", soapRequest.length);
xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/HelloWorld ");
xmlHttp.send(soapRequest);var responseXML=xmlHttp.responseXML;
alert(responseXML);
your code should be something like the above code,
in above code "http://tempuri.org/" is the default namespace url
what error you are getting?? could you paste you code
Mahain- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 7:56 AMModerator
All replies
-
You can use javascript to use external webservice in crm.
here is one link to use webservice through javascript
"http://blog.customereffective.com/blog/2008/02/calling-the-crm.html"
Mahain- Proposed as answer by Nishant RanaMVP Tuesday, June 2, 2009 4:55 AM
- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 4:44 AMModerator -
Here is the code to use external webservice in crm using JS
var soapRequest="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap="+
"\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<soap:Body>"+
"<webmethodname xmlns=\'http://tempuri.org/\'>"+
"<ParameterName>"+parameter+</ParameterName>"+
"</webmethodname>"+
" </soap:Body>"+
"</soap:Envelope>";var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("post","your externalweb service URL", false);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlHttp.setRequestHeader("Content-Length", soapRequest.length);
xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/webmethodname");
xmlHttp.send(soapRequest);var responseXML=xmlHttp.responseXML;
alert(responseXML);
Hope it will help
Mahain- Proposed as answer by Andrii ButenkoMVP, Moderator Tuesday, June 2, 2009 5:23 AM
- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 5:08 AMModerator -
Hi.
You can look article from SDK as sample of External Web Services call.
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Proposed as answer by Andrii ButenkoMVP, Moderator Tuesday, June 2, 2009 5:23 AM
- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 5:23 AMModerator -
Mahain,
Can you please explaint me some more about the code. I am getting some errors.
I have created my simple webservice that is running on localhost and the service has a methodname (HelloWorld) with one parameter (string Msg). Can you please tell me how i can change the above code accordingly? Please explain me the webservice namespace.
Appreciate your help in advance.Tuesday, June 2, 2009 7:43 AM -
Hi.
Look this thread .
I hope this will help you.
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 7:53 AMModerator -
var soapRequest="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap="+
"\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<soap:Body>"+
"<HelloWorld xmlns=\'http://tempuri.org/\'>"+
"<Msg>'Hello tusman'</Msg>"+
"</HelloWorld>"+
" </soap:Body>"+
"</soap:Envelope>";var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("post","your webservice url", false);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlHttp.setRequestHeader("Content-Length", soapRequest.length);
xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/HelloWorld ");
xmlHttp.send(soapRequest);var responseXML=xmlHttp.responseXML;
alert(responseXML);
your code should be something like the above code,
in above code "http://tempuri.org/" is the default namespace url
what error you are getting?? could you paste you code
Mahain- Marked as answer by Andrii ButenkoMVP, Moderator Friday, June 1, 2012 3:54 PM
Tuesday, June 2, 2009 7:56 AMModerator -
The following is my code. which i have pasted in OnSave event of the CRM form.
var soapRequest="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap="+
"\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<soap:Body>"+
"<HelloWorld xmlns=\'http://tempuri.org/\'>"+
"<Msg>"+Successfully Saved+</Msg>"+
"</HelloWorld>"+
" </soap:Body>"+
"</soap:Envelope>";var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("post","http://192.168.1.5:4444/Service.asmx", false);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlHttp.setRequestHeader("Content-Length", soapRequest.length);
xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/HelloWorld");
xmlHttp.send(soapRequest);var responseXML=xmlHttp.responseXML;
alert(responseXML);
Note. Crm dynamic error and says report to microsoft. error is not displayed.Tuesday, June 2, 2009 8:07 AM -
tusman,
i suggest you to debug your code to catch the error,
(you can debug your javascript by jut writing "debugger" keyword and setting ("Disabling script debugger") through internet options\Advance\Browsing
as well as create virtual directory under under IIS for you custum webservice and then try this code.
var soapRequest="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap="+
"\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<soap:Body>"+
"<HelloWorld xmlns=\'http://tempuri.org/\'>"+
"<Msg>'Successfully Saved'</Msg>"+
"</HelloWorld>"+
" </soap:Body>"+
"</soap:Envelope>";var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("post","custom webservice url", false);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlHttp.setRequestHeader("Content-Length", soapRequest.length);
xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/HelloWorld");
xmlHttp.send(soapRequest);var responseXML=xmlHttp.responseXML;
alert(responseXML);
hope it will help
MahainTuesday, June 2, 2009 9:11 AMModerator -
Mahain,
I have tested all the script and i think script is working fine. but it gets an error and error is Permission Denied. There is no user name and password for the Webservice.Can you please explain why this got an error.
I am using WebService from a local machine and CRM is on the server. Might be this is the reason.
Look at this thread .Tuesday, June 2, 2009 11:27 AM -
it means you are not able to access that webservice,try to access your webservice through IE first. if you are not able to access it without entering credentials then try to enable "Anonymous Access" for your webservice in server.
Hope it will help
MahainTuesday, June 2, 2009 11:41 AMModerator -
Mahain,
I give an anonymous access to my webservice. but still Permissin Denied Error is occur. Can you Please tell me that how we can provide credentials to our webservice and further how to access this webservice through javascript providing given credentials to it. I mean to say how we can secure our webservice and then access it to javascript. Gimme all ways to secure webservice...
Appreciate your help in advance.Wednesday, June 3, 2009 4:28 AM -
tusman ,
there is no need of passing credentials to your webservice i hope you are missing some setting.
try this.
where you have created virtual directory for you webservice, is it in ISV folder under ms crmweb or not ??????
1. try to make Application pool of your webserver same as of ms crm Application pool. i mean to say Application pool of your webservice should be same to ms crm Application pool .then try to access web service through IE first???
hope it will help.
MahainWednesday, June 3, 2009 4:41 AMModerator -
Mahain,
Actually my crm is on server and i created a webservice in a local machine. webservice is not placed in ISV folder. I think that is the problem what do you say?Wednesday, June 3, 2009 4:50 AM -
Ohh,
you have to publish your webservice to the server first,
try this
1. first publish your webservice to some folder in your local machine let say "Published web folder"
2. copy this folder to some location in server.
3. create virtual directory under ISV folder and direct to the location of the folder in the server.
4. set anonymous access on and Application pool same as of crm server.
then try to access your web.
Hope it will help.
MahainWednesday, June 3, 2009 4:55 AMModerator -
Ok Mahain Thanx....
But could not we use webservice from different machine but on the same network?? crm server and webservice is on same network but on different machine...... ????Wednesday, June 3, 2009 5:00 AM -
you can do that go through this article "http://msdn.microsoft.com/en-us/library/cc150839.aspx",
in that case you need to do some other settings also.
personally i have not tried this.
MahainWednesday, June 3, 2009 5:13 AMModerator -
Ok mahain thanx for your kind help..Can you please gimme your email id where we can discuss problems or having chat..
my email id is alienz_@hotmail.com.
Appreciate your help once again.Wednesday, June 3, 2009 5:27 AM