CRM 온라인을 쿼리 할 때 basicHttpBinding
이 아닌 wsHttpBinding
을 통해 요청을 보내도록 ASP.NET 웹 양식을 구성하는 방법은 무엇입니까?CRM 온라인을 쿼리 할 때 wsHttpBinding을 사용하도록 ASP.NET 웹 페이지를 구성하려면 어떻게합니까?
약간의 배경으로 IIS 8.5에서 로컬로 호스팅되는 아주 기본적인 ASPX 페이지입니다.
페이지는 CRM Online에 연결하고 일부 데이터를 가져 오기위한 것입니다.
편집 :이 앱은 Azure AD를 통해 인증되므로 클라이언트 ID와 키가 사용됩니다. 내가 피할 수없는 경우가 아니면 연결 문자열과 도메인 자격 증명을 사용하는 것을 꺼려합니다.
은 내가 올바른 CRM에 대한 인증을 가지고 생각하지만 난 쿼리를 실행할 때 아래 오류가 나타납니다 : 내가 지정하지 않은 때문이라고 생각
System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'..
web.config
바인딩 때문에 내 페이지가 basicHttpBinding
을 통해 모든 것을 전송하고 있으며 CRM 온라인 인터페이스가 wsHttpBinding
일 것으로 예상됩니다.
this MSDN article (및 그 변형)의 하단에있는 예제를 사용해 보았지만 아무런 차이가 없습니다.
차이점을 대비하여 CRM에 연결하기위한 코드는 다음과 같습니다. 분명히 나는 실제 구성 세부 사항을 모호하게했다.
[WebException: The remote server returned an error: (415) Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'..] System.Net.HttpWebRequest.GetResponse() +1740 System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +75
[ProtocolException: Content Type text/xml; charset=utf-8 was not supported by service https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc . The client and service bindings may be mismatched.] System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +14350190 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +388 Microsoft.Xrm.Sdk.IOrganizationService.RetrieveMultiple(QueryBase query) +0 Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient
1.ExecuteAction(Func
1 action) +51 Quote_Robot_Demo.d__4.MoveNext() +887 System.Runtime.CompilerServices.<>c.b__6_0(Object state) +56 System.Web.Util.SynchronizationHelper.SafeWrapCallback(Action action) +110 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13847892 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 System.Web.Util.WithinCancellableCallbackTaskAwaiter.GetResult() +32 System.Web.UI.d__523.MoveNext() +7970
편집 : 여기
// CONFIGURE OAUTH
var tenantName = "mycompany.onmicrosoft.com";
var authString = string.Format(@"https://login.microsoftonline.com/{0}",tenantName);
var authContext = new AuthenticationContext(authString, false);
var clientId = "123ab123-123a-1a23-abcd-1a2345612345";
var key = "nStgfrdk0oyaC1P5+/FQ4wGn4fRgUTr8HTKejytf0bv=";
var clientCred = new ClientCredential(clientId, key);
var resource = "https://myinstance.crm4.dynamics.com";
// ACQUIRE THE AUTH TOKEN
var authResult = await authContext.AcquireTokenAsync(resource, clientCred);
// CREATE THE CONNECTION TO CRM
var orgService = new OrganizationWebProxyClient(
new Uri("https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc"), true)
{
HeaderToken = authResult.AccessToken,
SdkClientVersion = "8.1.0"
};
// RUNNING THIS QUERY CAUSES THE ERROR
var contacts = orgService.RetrieveMultiple(new QueryExpression
{
EntityName = "contact",
ColumnSet = new ColumnSet("firstname", "lastname")
})
.Entities
.Select(item => item.ToEntity<Contact>());
은 사용의의 경우 스택 추적의 나는 비록
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IDiscoveryService">
<textMessageEncoding />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc"
binding="customBinding" bindingConfiguration="CustomBinding_IDiscoveryService"
contract="CRMService.IDiscoveryService" name="CustomBinding_IDiscoveryService" />
</client>
</system.serviceModel>
바퀴를 다시 만들어야하는 이유는 무엇입니까? https://msdn.microsoft.com/en-us/library/gg695810(v=crm.7).aspx – dynamicallyCRM
이 앱이 Azure AD를 통해 인증되도록 지정해야합니다.이 앱은 고유 한 클라이언트 ID와 키를 사용합니다. Azure로 로그인하십시오. SDK 예제는 연결 문자열을 사용하지만 Windows 자격 증명이 필요하므로이를 원하지 않습니다. 내 질문에 대해 더 구체적으로 편집 해 보겠습니다. – Equalsk
CRM SDK는 온 프레미스 설치만을위한 것이 아니며 CRM 온라인 버전도 지원하므로 앱 호스팅 방법에 관계없이 SDK를 사용하여 호스팅 방식과 관계없이 CRM 인스턴스에 연결할 수 있습니다. 또한 백그라운드의 SDK는 달성하려는 작업을 정확히 수행하며 모든 통신 채널을 처리합니다. – dynamicallyCRM