Hi.

I'm trying to call a custom made web service from a custom entity form. All
i get is nothing. Altough my code is ok (i guess), i have some questions if
someone can help me out.

Situation is this:

On a custom entity form, i have two text boxe. In the first one, input a
numeric code, with a POST request this code is send to a web service. Then,
the web service take this code and in their code transforms the code into
words. If i input 120, the web service returns "one hundred twenty".

Question: i really need to reference crm web services (CrmService and
MetadataService in my OWN CUSTOM WEB SERVICE?).

Question Number 2: this is my code. What i'm doing wrong?

var sOut;
var sIn = "";
var objSend;

var f = NumeroPalabras(sIn)
{
return sOut;
}

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

strEnvelope = "<soap:Envelope
xmlns:xsi=\"http//www.w3.org/2001/XMLSchema-instance\"" +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
"xmlns:soap=\http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" + "<" + "NumeroPalabra" + "
xmlns="\http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/\">" +
"</soap:Body>" + "</soap:Envelope>";

// Seteamos el POST...
xmlhttp.onreadystatechange = function()
{
// Un readyState de 4 significa que estamos listos para usar los
datos
// retornados.
if (xmlhttp.readyState = 4)
{
// Obtenemos de vuelta el envelope XML.
var szResponse = xmlhttp.responseText;

var startTag = "<string xmlns=\"http://192.168.0.21:5153/" +
"WebServices/NumeroStringService.asmx\">";

var endTag = "</string>";

var valueStart = 0;
var valueEnd = 0;

// Parseamos el XML retornado.
valueStart = xmlhttp.responseXML.xml.indexOf(startTag, valueEnd)
+ startTag.length;

valueEnd = xmlhttp.responseXml.xml.indexOf(endTag, valueEnd+1);

var tmp = xmlhttp.responseXML.xml.substring(valueStart, valueEnd);

var szUrl =
"http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/NumeroPalabras";

// Enviamos el POST
xmlhttp.open("POST", szUrl, true);
xmlhttp.setRequestHeader(Content-Type",
"application/x-www-form-urlencoded");
xmlhttp.send(strEnvelope);

alert("El valor es: " + tmp);
}
}

I really hope someone could help me. Sorry my english. No english native
person here.

Regards, dejavu.

Re: Web Services and JScript in CRM Custom Entity by Ernst

Ernst
Fri Aug 25 04:49:57 CDT 2006

Hi Dejavu,

Firstly, you need to reference only the webservices that you are
consuming.

Secondly, I would advice you to, rather than building up SOAP packets
in JavaScript and then trying to parse the result, just send your
request to a normal aspx page, which in turn returns an easily parsable
text result. This enables you to do the webservice calls in C#, and
debug them better (by using Visual Studio).

Hope this helps! Ask if you need more information.

--
Ernst Kuschke
MVP - C#
http://dotnet.org.za/ernst

dejavu wrote:
> Hi.
>
> I'm trying to call a custom made web service from a custom entity form. All
> i get is nothing. Altough my code is ok (i guess), i have some questions if
> someone can help me out.
>
> Situation is this:
>
> On a custom entity form, i have two text boxe. In the first one, input a
> numeric code, with a POST request this code is send to a web service. Then,
> the web service take this code and in their code transforms the code into
> words. If i input 120, the web service returns "one hundred twenty".
>
> Question: i really need to reference crm web services (CrmService and
> MetadataService in my OWN CUSTOM WEB SERVICE?).
>
> Question Number 2: this is my code. What i'm doing wrong?
>
> var sOut;
> var sIn = "";
> var objSend;
>
> var f = NumeroPalabras(sIn)
> {
> return sOut;
> }
>
> var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
>
> strEnvelope = "<soap:Envelope
> xmlns:xsi=\"http//www.w3.org/2001/XMLSchema-instance\"" +
> "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
> "xmlns:soap=\http://schemas.xmlsoap.org/soap/envelope/\">" +
> "<soap:Body>" + "<" + "NumeroPalabra" + "
> xmlns="\http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/\">" +
> "</soap:Body>" + "</soap:Envelope>";
>
> // Seteamos el POST...
> xmlhttp.onreadystatechange = function()
> {
> // Un readyState de 4 significa que estamos listos para usar los
> datos
> // retornados.
> if (xmlhttp.readyState = 4)
> {
> // Obtenemos de vuelta el envelope XML.
> var szResponse = xmlhttp.responseText;
>
> var startTag = "<string xmlns=\"http://192.168.0.21:5153/" +
> "WebServices/NumeroStringService.asmx\">";
>
> var endTag = "</string>";
>
> var valueStart = 0;
> var valueEnd = 0;
>
> // Parseamos el XML retornado.
> valueStart = xmlhttp.responseXML.xml.indexOf(startTag, valueEnd)
> + startTag.length;
>
> valueEnd = xmlhttp.responseXml.xml.indexOf(endTag, valueEnd+1);
>
> var tmp = xmlhttp.responseXML.xml.substring(valueStart, valueEnd);
>
> var szUrl =
> "http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/NumeroPalabras";
>
> // Enviamos el POST
> xmlhttp.open("POST", szUrl, true);
> xmlhttp.setRequestHeader(Content-Type",
> "application/x-www-form-urlencoded");
> xmlhttp.send(strEnvelope);
>
> alert("El valor es: " + tmp);
> }
> }
>
> I really hope someone could help me. Sorry my english. No english native
> person here.
>
> Regards, dejavu.


Re: Web Services and JScript in CRM Custom Entity by dejavu

dejavu
Fri Aug 25 08:39:02 CDT 2006

Thanks Ernst, i really apreciate your answer. I have a couple of questions
now...you said that i can use an aspx page to return the text that i want to
use. But, in this case when i need to send from CRM and return to CRM the
same value but modified, is really necessary to make an aspx page?

Secondly, how can i call the webservice from OnChange if i don't use SOAP?

I'm just a newbie in CRM, i apologize if my questions sounds dumb!!!

Thanx u again!

best regards.

"Ernst Kuschke (C# MVP)" wrote:

> Hi Dejavu,
>
> Firstly, you need to reference only the webservices that you are
> consuming.
>
> Secondly, I would advice you to, rather than building up SOAP packets
> in JavaScript and then trying to parse the result, just send your
> request to a normal aspx page, which in turn returns an easily parsable
> text result. This enables you to do the webservice calls in C#, and
> debug them better (by using Visual Studio).
>
> Hope this helps! Ask if you need more information.
>
> --
> Ernst Kuschke
> MVP - C#
> http://dotnet.org.za/ernst
>
> dejavu wrote:
> > Hi.
> >
> > I'm trying to call a custom made web service from a custom entity form. All
> > i get is nothing. Altough my code is ok (i guess), i have some questions if
> > someone can help me out.
> >
> > Situation is this:
> >
> > On a custom entity form, i have two text boxe. In the first one, input a
> > numeric code, with a POST request this code is send to a web service. Then,
> > the web service take this code and in their code transforms the code into
> > words. If i input 120, the web service returns "one hundred twenty".
> >
> > Question: i really need to reference crm web services (CrmService and
> > MetadataService in my OWN CUSTOM WEB SERVICE?).
> >
> > Question Number 2: this is my code. What i'm doing wrong?
> >
> > var sOut;
> > var sIn = "";
> > var objSend;
> >
> > var f = NumeroPalabras(sIn)
> > {
> > return sOut;
> > }
> >
> > var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
> >
> > strEnvelope = "<soap:Envelope
> > xmlns:xsi=\"http//www.w3.org/2001/XMLSchema-instance\"" +
> > "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
> > "xmlns:soap=\http://schemas.xmlsoap.org/soap/envelope/\">" +
> > "<soap:Body>" + "<" + "NumeroPalabra" + "
> > xmlns="\http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/\">" +
> > "</soap:Body>" + "</soap:Envelope>";
> >
> > // Seteamos el POST...
> > xmlhttp.onreadystatechange = function()
> > {
> > // Un readyState de 4 significa que estamos listos para usar los
> > datos
> > // retornados.
> > if (xmlhttp.readyState = 4)
> > {
> > // Obtenemos de vuelta el envelope XML.
> > var szResponse = xmlhttp.responseText;
> >
> > var startTag = "<string xmlns=\"http://192.168.0.21:5153/" +
> > "WebServices/NumeroStringService.asmx\">";
> >
> > var endTag = "</string>";
> >
> > var valueStart = 0;
> > var valueEnd = 0;
> >
> > // Parseamos el XML retornado.
> > valueStart = xmlhttp.responseXML.xml.indexOf(startTag, valueEnd)
> > + startTag.length;
> >
> > valueEnd = xmlhttp.responseXml.xml.indexOf(endTag, valueEnd+1);
> >
> > var tmp = xmlhttp.responseXML.xml.substring(valueStart, valueEnd);
> >
> > var szUrl =
> > "http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/NumeroPalabras";
> >
> > // Enviamos el POST
> > xmlhttp.open("POST", szUrl, true);
> > xmlhttp.setRequestHeader(Content-Type",
> > "application/x-www-form-urlencoded");
> > xmlhttp.send(strEnvelope);
> >
> > alert("El valor es: " + tmp);
> > }
> > }
> >
> > I really hope someone could help me. Sorry my english. No english native
> > person here.
> >
> > Regards, dejavu.
>
>

Re: Web Services and JScript in CRM Custom Entity by Ernst

Ernst
Mon Aug 28 03:14:47 CDT 2006

Hi,

It would work as follows:

Create an aspx page that accepts parameters specifying what you would
like to do. An example could be:

http://yourWebserver/CrmIntegration.aspx?method=ChangeValue&param=value

The aspx page would call the webservice you need to call (instead of
calling it from JavaScript), and return the changed value by doing a
Response.Write(...), for example.

So in your JavaScript, you could call the aspx page "AJAX-like" as
follows:

function ChangeMyValue(valueToChange)
{
if((valueToChange == "") || (valueToChange == null))
return valueToChange;

GetXmlHttp();

var url = webservice_location + "?method=ChangeValue&param=" +
valueToChange;

if(xmlhttp != null)
{
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
}

return xmlhttp.responseText;
}

This enables you to call the webservice, but from C#, which is just way
nicer than JavaScript to debug, or do anything complicated in (like
calling webservices).

Does that help? Hope so!

-Ernst

dejavu wrote:
> Thanks Ernst, i really apreciate your answer. I have a couple of questions
> now...you said that i can use an aspx page to return the text that i want to
> use. But, in this case when i need to send from CRM and return to CRM the
> same value but modified, is really necessary to make an aspx page?
>
> Secondly, how can i call the webservice from OnChange if i don't use SOAP?
>
> I'm just a newbie in CRM, i apologize if my questions sounds dumb!!!
>
> Thanx u again!
>
> best regards.
>
> "Ernst Kuschke (C# MVP)" wrote:
>
> > Hi Dejavu,
> >
> > Firstly, you need to reference only the webservices that you are
> > consuming.
> >
> > Secondly, I would advice you to, rather than building up SOAP packets
> > in JavaScript and then trying to parse the result, just send your
> > request to a normal aspx page, which in turn returns an easily parsable
> > text result. This enables you to do the webservice calls in C#, and
> > debug them better (by using Visual Studio).
> >
> > Hope this helps! Ask if you need more information.
> >
> > --
> > Ernst Kuschke
> > MVP - C#
> > http://dotnet.org.za/ernst
> >
> > dejavu wrote:
> > > Hi.
> > >
> > > I'm trying to call a custom made web service from a custom entity form. All
> > > i get is nothing. Altough my code is ok (i guess), i have some questions if
> > > someone can help me out.
> > >
> > > Situation is this:
> > >
> > > On a custom entity form, i have two text boxe. In the first one, input a
> > > numeric code, with a POST request this code is send to a web service. Then,
> > > the web service take this code and in their code transforms the code into
> > > words. If i input 120, the web service returns "one hundred twenty".
> > >
> > > Question: i really need to reference crm web services (CrmService and
> > > MetadataService in my OWN CUSTOM WEB SERVICE?).
> > >
> > > Question Number 2: this is my code. What i'm doing wrong?
> > >
> > > var sOut;
> > > var sIn = "";
> > > var objSend;
> > >
> > > var f = NumeroPalabras(sIn)
> > > {
> > > return sOut;
> > > }
> > >
> > > var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
> > >
> > > strEnvelope = "<soap:Envelope
> > > xmlns:xsi=\"http//www.w3.org/2001/XMLSchema-instance\"" +
> > > "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
> > > "xmlns:soap=\http://schemas.xmlsoap.org/soap/envelope/\">" +
> > > "<soap:Body>" + "<" + "NumeroPalabra" + "
> > > xmlns="\http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/\">" +
> > > "</soap:Body>" + "</soap:Envelope>";
> > >
> > > // Seteamos el POST...
> > > xmlhttp.onreadystatechange = function()
> > > {
> > > // Un readyState de 4 significa que estamos listos para usar los
> > > datos
> > > // retornados.
> > > if (xmlhttp.readyState = 4)
> > > {
> > > // Obtenemos de vuelta el envelope XML.
> > > var szResponse = xmlhttp.responseText;
> > >
> > > var startTag = "<string xmlns=\"http://192.168.0.21:5153/" +
> > > "WebServices/NumeroStringService.asmx\">";
> > >
> > > var endTag = "</string>";
> > >
> > > var valueStart = 0;
> > > var valueEnd = 0;
> > >
> > > // Parseamos el XML retornado.
> > > valueStart = xmlhttp.responseXML.xml.indexOf(startTag, valueEnd)
> > > + startTag.length;
> > >
> > > valueEnd = xmlhttp.responseXml.xml.indexOf(endTag, valueEnd+1);
> > >
> > > var tmp = xmlhttp.responseXML.xml.substring(valueStart, valueEnd);
> > >
> > > var szUrl =
> > > "http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/NumeroPalabras";
> > >
> > > // Enviamos el POST
> > > xmlhttp.open("POST", szUrl, true);
> > > xmlhttp.setRequestHeader(Content-Type",
> > > "application/x-www-form-urlencoded");
> > > xmlhttp.send(strEnvelope);
> > >
> > > alert("El valor es: " + tmp);
> > > }
> > > }
> > >
> > > I really hope someone could help me. Sorry my english. No english native
> > > person here.
> > >
> > > Regards, dejavu.
> >
> >


Re: Web Services and JScript in CRM Custom Entity by dejavu

dejavu
Mon Oct 02 09:27:02 CDT 2006

wow...what can i say. Last reply was nice Ernst i really apreciate your help
mate.

I apologize the slow answer i gave it to you, so much work in here waiting
to be competed.

But anyway, your answer was very helpful. I'm in process to understanding
how XML works, to develop things based on SOAP. But, roght now i'm going to
implement your sugestion about the aspx .net page.

Again, thank you very much Ernst.

Regards, dejavu.

"Ernst Kuschke (C# MVP)" wrote:

> Hi,
>
> It would work as follows:
>
> Create an aspx page that accepts parameters specifying what you would
> like to do. An example could be:
>
> http://yourWebserver/CrmIntegration.aspx?method=ChangeValue&param=value
>
> The aspx page would call the webservice you need to call (instead of
> calling it from JavaScript), and return the changed value by doing a
> Response.Write(...), for example.
>
> So in your JavaScript, you could call the aspx page "AJAX-like" as
> follows:
>
> function ChangeMyValue(valueToChange)
> {
> if((valueToChange == "") || (valueToChange == null))
> return valueToChange;
>
> GetXmlHttp();
>
> var url = webservice_location + "?method=ChangeValue&param=" +
> valueToChange;
>
> if(xmlhttp != null)
> {
> xmlhttp.open("GET", url, false);
> xmlhttp.send(null);
> }
>
> return xmlhttp.responseText;
> }
>
> This enables you to call the webservice, but from C#, which is just way
> nicer than JavaScript to debug, or do anything complicated in (like
> calling webservices).
>
> Does that help? Hope so!
>
> -Ernst
>
> dejavu wrote:
> > Thanks Ernst, i really apreciate your answer. I have a couple of questions
> > now...you said that i can use an aspx page to return the text that i want to
> > use. But, in this case when i need to send from CRM and return to CRM the
> > same value but modified, is really necessary to make an aspx page?
> >
> > Secondly, how can i call the webservice from OnChange if i don't use SOAP?
> >
> > I'm just a newbie in CRM, i apologize if my questions sounds dumb!!!
> >
> > Thanx u again!
> >
> > best regards.
> >
> > "Ernst Kuschke (C# MVP)" wrote:
> >
> > > Hi Dejavu,
> > >
> > > Firstly, you need to reference only the webservices that you are
> > > consuming.
> > >
> > > Secondly, I would advice you to, rather than building up SOAP packets
> > > in JavaScript and then trying to parse the result, just send your
> > > request to a normal aspx page, which in turn returns an easily parsable
> > > text result. This enables you to do the webservice calls in C#, and
> > > debug them better (by using Visual Studio).
> > >
> > > Hope this helps! Ask if you need more information.
> > >
> > > --
> > > Ernst Kuschke
> > > MVP - C#
> > > http://dotnet.org.za/ernst
> > >
> > > dejavu wrote:
> > > > Hi.
> > > >
> > > > I'm trying to call a custom made web service from a custom entity form. All
> > > > i get is nothing. Altough my code is ok (i guess), i have some questions if
> > > > someone can help me out.
> > > >
> > > > Situation is this:
> > > >
> > > > On a custom entity form, i have two text boxe. In the first one, input a
> > > > numeric code, with a POST request this code is send to a web service. Then,
> > > > the web service take this code and in their code transforms the code into
> > > > words. If i input 120, the web service returns "one hundred twenty".
> > > >
> > > > Question: i really need to reference crm web services (CrmService and
> > > > MetadataService in my OWN CUSTOM WEB SERVICE?).
> > > >
> > > > Question Number 2: this is my code. What i'm doing wrong?
> > > >
> > > > var sOut;
> > > > var sIn = "";
> > > > var objSend;
> > > >
> > > > var f = NumeroPalabras(sIn)
> > > > {
> > > > return sOut;
> > > > }
> > > >
> > > > var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
> > > >
> > > > strEnvelope = "<soap:Envelope
> > > > xmlns:xsi=\"http//www.w3.org/2001/XMLSchema-instance\"" +
> > > > "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
> > > > "xmlns:soap=\http://schemas.xmlsoap.org/soap/envelope/\">" +
> > > > "<soap:Body>" + "<" + "NumeroPalabra" + "
> > > > xmlns="\http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/\">" +
> > > > "</soap:Body>" + "</soap:Envelope>";
> > > >
> > > > // Seteamos el POST...
> > > > xmlhttp.onreadystatechange = function()
> > > > {
> > > > // Un readyState de 4 significa que estamos listos para usar los
> > > > datos
> > > > // retornados.
> > > > if (xmlhttp.readyState = 4)
> > > > {
> > > > // Obtenemos de vuelta el envelope XML.
> > > > var szResponse = xmlhttp.responseText;
> > > >
> > > > var startTag = "<string xmlns=\"http://192.168.0.21:5153/" +
> > > > "WebServices/NumeroStringService.asmx\">";
> > > >
> > > > var endTag = "</string>";
> > > >
> > > > var valueStart = 0;
> > > > var valueEnd = 0;
> > > >
> > > > // Parseamos el XML retornado.
> > > > valueStart = xmlhttp.responseXML.xml.indexOf(startTag, valueEnd)
> > > > + startTag.length;
> > > >
> > > > valueEnd = xmlhttp.responseXml.xml.indexOf(endTag, valueEnd+1);
> > > >
> > > > var tmp = xmlhttp.responseXML.xml.substring(valueStart, valueEnd);
> > > >
> > > > var szUrl =
> > > > "http://192.168.0.21:5153/WebServices/NumeroStringService.asmx/NumeroPalabras";
> > > >
> > > > // Enviamos el POST
> > > > xmlhttp.open("POST", szUrl, true);
> > > > xmlhttp.setRequestHeader(Content-Type",
> > > > "application/x-www-form-urlencoded");
> > > > xmlhttp.send(strEnvelope);
> > > >
> > > > alert("El valor es: " + tmp);
> > > > }
> > > > }
> > > >
> > > > I really hope someone could help me. Sorry my english. No english native
> > > > person here.
> > > >
> > > > Regards, dejavu.
> > >
> > >
>
>