|  20.02.2011, 08:42 | #1 | 
| Участник |  SoapException 
			
			На Форму, на событие OnLoad поместил скрипт: Код: function GetAttributeValueByEntityId(entityName, entytiId, attributeName)
{
    var xml = '' + 
    '[?xml version=`1.0` encoding=`utf-8`?]' + '\r\n' + 
    '[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`]' + '\r\n' + 
    ' [soap:Body]' + '\r\n' + 
    ' [entityName xmlns=`http://srv/mscrmservices/2006/WebServices`]' + entityName + '[/entityName]' + '\r\n' + 
    ' [id xmlns=`http://srv/mscrmservices/2006/WebServices`]' + entytiId + '[/id]' + '\r\n' + 
    ' [columnSet xmlns=`http://srv/mscrmservices/2006/WebServices` xmlns:q=`http://srv/mscrmservicesa/2006/Query` xsi:type=`q:ColumnSet`]' + '\r\n' + 
    ' [q:Attributes]' + '\r\n' +
    ' [q:Attribute]' + attributeName + '[/q:Attribute]' + '\r\n' +
    ' [/q:Attributes]' + '\r\n' +
    ' [/columnSet]' + '\r\n' + 
    ' [/soap:Body]' + '\r\n' + 
    '[/soap:Envelope]' + 
    '';
    xml = xml.replace(/\[/gi, String.fromCharCode(60));
    xml = xml.replace(/\]/gi, String.fromCharCode(62));
    xml = xml.replace(/\`/gi, String.fromCharCode(34));
    var xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
    xmlHttpRequest.Open('POST', '/mscrmservices/2006/CrmService.asmx', false);
    xmlHttpRequest.setRequestHeader('SOAPAction','http://srv/mscrmservices/2006/WebServices/Retrieve');
    xmlHttpRequest.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    xmlHttpRequest.setRequestHeader('Content-Length', xml.length);
    xmlHttpRequest.send(xml);
    var doc = xmlHttpRequest.responseXML;
//    alert(xmlHttpRequest.responseText);
    var retValue = '';
    if (doc.selectSingleNode('//RetrieveResult/' + attributeName) != null) retValue = doc.selectSingleNode('//RetrieveResult/' + attributeName).text;
    return retValue;
}Код: alert(GetAttributeValueByEntityId('account', 'CAC2A1FB-0CD6-DC11-828D-00151722E585', 'name'));Код: --------------------------- Сообщение с веб-страницы --------------------------- <?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> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>System.Web.Services.Protocols.SoapException: Сервер не распознал заголовок HTTP SOAPAction: http://srv/mscrmservices/2006/WebServices/Retrieve. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)</faultstring> <detail /> </soap:Fault> </soap:Body> </soap:Envelope> --------------------------- ОК --------------------------- | 
|  | 
|  20.02.2011, 10:22 | #2 | 
| Moderator | 
			
			Так точно,сер! Ваш уродливый скрипт написан под CRM 3.0 и не будет работать по 4.0! p.s. Вы не в support пишите. Будьте вежливы и может быть получите хороший ответ. p.p.s. В SDK есть несколько примеров обращений к веб сервисам системы через JavaScript. Там же рассказывается как правильно формировать заголовок запроса. 
				__________________ http://fixrm.wordpress.com, снятие/наведение порчи. Быстро, дорого, гарантия.   MS Certified Dirty Magic Professional | 
|  | 
|  20.02.2011, 10:38 | #3 | 
| Участник | Цитата: 
		
			Сообщение от Артем Enot Грунин
			   Так точно,сер! Ваш уродливый скрипт написан под CRM 3.0 и не будет работать по 4.0! p.s. Вы не в support пишите. Будьте вежливы и может быть получите хороший ответ. p.p.s. В SDK есть несколько примеров обращений к веб сервисам системы через JavaScript. Там же рассказывается как правильно формировать заголовок запроса. Но вашему совету последую, поищу в SDK. | 
|  | 
|  20.02.2011, 21:47 | #4 | 
| Участник | 
			
			Спасибо Артем Enot Грунин, решил проблему, проблема была в незнании   Вот так всё работает: Код: function GetAttributeValueByEntityId(entityName, entytiId, attributeName)
{
var xml = "[?xml version='1.0' encoding='utf-8'?]" + "\r\n" +
"[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']" + "\r\n" +
" [soap:Body]" + "\r\n" +
" [entityName xmlns='http://schemas.microsoft.com/crm/2006/WebServices']" + entityName + "[/entityName]" + "\r\n" +
" [id xmlns='http://schemas.microsoft.com/crm/2006/WebServices']" + entytiId + "[/id]" + "\r\n" +
" [columnSet xmlns='http://schemas.microsoft.com/crm/2006/WebServices' xmlns:q='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q:ColumnSet']" + "\r\n" +
" [q:Attributes]" + "\r\n" +
" [q:Attribute]" + attributeName + "[/q:Attribute]" + "\r\n" +
" [/q:Attributes]" + "\r\n" +
" [/columnSet]" + "\r\n" +
" [/soap:Body]" + "\r\n" +
"[/soap:Envelope]";
 
xml = xml.replace(/\[/gi, String.fromCharCode(60));
xml = xml.replace(/\]/gi, String.fromCharCode(62));
var xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
xmlHttpRequest.Open('POST', '/mscrmservices/2006/CrmService.asmx', false);
xmlHttpRequest.setRequestHeader('SOAPAction','http://schemas.microsoft.com/crm/2006/WebServices/Retrieve');
xmlHttpRequest.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlHttpRequest.setRequestHeader('Content-Length', xml.length);
xmlHttpRequest.send(xml);
var doc = xmlHttpRequest.responseXML;
alert(xmlHttpRequest.responseText);
var retValue = '';
if (doc.selectSingleNode('//RetrieveResult/' + attributeName) != null)
    retValue = doc.selectSingleNode('//RetrieveResult/' + attributeName).text;
   
return retValue;
};
 
crmForm.all.new_orderyrnaz.DataValue = GetAttributeValueByEntityId('account', crmForm.all.customerid.DataValue[0].id, 'new_yrnaz') | 
|  | 
|  21.02.2011, 09:33 | #5 | 
| Moderator | 
			
			Не за что, вы все равно не воспользовались моим советом, верно?   По сути вы поправили заголовок запроса но в нем все равно используются точки совместимости с 3.0: crm/2006/WebServices/ Код: xmlHttpRequest.setRequestHeader('SOAPAction','http://schemas.microsoft.com/crm/2006/WebServices/Retrieve');Код: // Prepare variables for a contact to retrieve.
var contactid = "4696f8cb-9a1c-dd11-ad3a-0003ff9ee217";
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = "<?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'>"+ 
authenticationHeader+ 
"<soap:Body>"+ 
"<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ 
"<entityName>contact</entityName>"+ 
"<id>"+contactid+"</id>"+ 
"<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ 
"<q1:Attributes>"+ 
"<q1:Attribute>fullname</q1:Attribute>"+ 
"</q1:Attributes>"+ 
"</columnSet>"+ 
"</Retrieve>"+ 
"</soap:Body>"+ 
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
 var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
 alert(msg);
}
// Display the retrieved value.
else
{
alert(resultXml.selectSingleNode("//q1:fullname").nodeTypedValue);
				__________________ http://fixrm.wordpress.com, снятие/наведение порчи. Быстро, дорого, гарантия.   MS Certified Dirty Magic Professional | 
|  | 
|  21.02.2011, 11:21 | #6 | 
| Участник |   Цитата:  http://msdn.microsoft.com/en-us/library/cc677076.aspx А вот тут у меня возникает ошибка, не стал в ней разбираться, пропустил этот шаг, вроде все работает. | 
|  | 
|  21.02.2011, 12:58 | #7 | 
| Moderator | 
			
			Что ж, тогда уточняйте, пожалуйста, в вопросе номер версии версии. Дело в том, что по тройке не часто спрашивают. На дворе уже пятая версия.    
				__________________ http://fixrm.wordpress.com, снятие/наведение порчи. Быстро, дорого, гарантия.   MS Certified Dirty Magic Professional | 
|  |