SSIS 2008 - 使用脚本组件连接到 CRM 2011 Web 服务

发布于 2024-11-26 10:17:48 字数 2578 浏览 0 评论 0原文

我正在尝试从无法利用 .Net 4 程序集的 SSIS 2008 脚本组件连接到 CRM 2011 Web 服务端点。这排除了 .Net 4 SDK,因此我一直在尝试创建一个代理类来直接针对 2011 WS 工作。我已经通过将该代理类放入其自己的程序集中来使代码正常工作,但它依赖于从 app.config 中读取 WS 地址(方法 1),SSIS 包无法使用该地址(那些用户可配置的属性需要存储在 SSIS 变量中,以便客户可以修改它们以在其环境中工作)。

我想弄清楚如何从 SSIS 包中读取 app.config 数据...

或者我需要让方法 2 之类的东西起作用,但不确定为什么服务器会抛出它所发生的错误。凭证是正确的。 OrganizationServiceClient 方法有几个重载,我已经尝试过,但没有一个起作用。这是我最接近让它发挥作用的一次。谁能告诉我我做错了什么?

            //Method 1:  This code works but relies on pulling the endpoint address from the app.config  (SSIS can’t use this method)
        //OrganizationServiceClient serviceClient = new OrganizationServiceClient("CustomBinding_IOrganizationService");
        //serviceClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential() { Domain="MyDomain", UserName="administrator", Password="*****" };

//Method 2:  This method throws this error:
//Could not connect to https:// MYSERVER/XrmServices/2011/Organization.svc. TCP error code 10061: No connection could be made because the target machine actively refused it.
        string url = "https:// MYSERVER/XrmServices/2011/Organization.svc";
        BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
        binding.MaxReceivedMessageSize = 2147483647;
        OrganizationServiceClient serviceClient = new OrganizationServiceClient(binding, new EndpointAddress(url));
        serviceClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential() { Domain=" MyDomain ", UserName="administrator", Password="******" };

            //this code is common between the two techniques above
        KeyValuePairOfstringanyType[] attributes = new KeyValuePairOfstringanyType[1];
        attributes[0] = new KeyValuePairOfstringanyType();
        attributes[0].key = "name";
        attributes[0].value = "MyTestAccount";

        Entity newAccount = new Entity();
        newAccount.LogicalName = "account";
        newAccount.Attributes = attributes;
        serviceClient.Create(newAccount);

下面的 app.config 部分(上面的方法 1 使用):

    <client>
        <endpoint address="http://MYSERVER/XRMServices/2011/Organization.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_IOrganizationService"
            contract="IOrganizationService" name="CustomBinding_IOrganizationService">
            <identity>
                <userPrincipalName value="*******" />
            </identity>
        </endpoint>
    </client>

I’m trying to connect to the CRM 2011 Web service endpoints from an SSIS 2008 Script component which can’t utilize .Net 4 assemblies. This rules out the .Net 4 SDK so I’ve been trying to create a proxy class to use to work directly against the 2011 WS. I’ve gotten the code to work by putting that proxy class into it's own assembly but it relies on reading the WS address from the app.config (method 1) which the SSIS packages can’t use (those user configurable attributes need to be stored in SSIS variables so the customer can modify them to work in their environment).

I'd like to figure out how to read app.config data from within a SSIS package...

Or I need to get something like method 2 working but am not sure why the server is throwing the error it does. The credentials are correct. The OrganizationServiceClient method has several overloads that I’ve tried and none have worked. This is the closest I’ve gotten to getting it working. Can anyone tell me what I’m doing wrong?

            //Method 1:  This code works but relies on pulling the endpoint address from the app.config  (SSIS can’t use this method)
        //OrganizationServiceClient serviceClient = new OrganizationServiceClient("CustomBinding_IOrganizationService");
        //serviceClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential() { Domain="MyDomain", UserName="administrator", Password="*****" };

//Method 2:  This method throws this error:
//Could not connect to https:// MYSERVER/XrmServices/2011/Organization.svc. TCP error code 10061: No connection could be made because the target machine actively refused it.
        string url = "https:// MYSERVER/XrmServices/2011/Organization.svc";
        BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
        binding.MaxReceivedMessageSize = 2147483647;
        OrganizationServiceClient serviceClient = new OrganizationServiceClient(binding, new EndpointAddress(url));
        serviceClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential() { Domain=" MyDomain ", UserName="administrator", Password="******" };

            //this code is common between the two techniques above
        KeyValuePairOfstringanyType[] attributes = new KeyValuePairOfstringanyType[1];
        attributes[0] = new KeyValuePairOfstringanyType();
        attributes[0].key = "name";
        attributes[0].value = "MyTestAccount";

        Entity newAccount = new Entity();
        newAccount.LogicalName = "account";
        newAccount.Attributes = attributes;
        serviceClient.Create(newAccount);

Part of the app.config below (used by method 1 above):

    <client>
        <endpoint address="http://MYSERVER/XRMServices/2011/Organization.svc"
            binding="customBinding" bindingConfiguration="CustomBinding_IOrganizationService"
            contract="IOrganizationService" name="CustomBinding_IOrganizationService">
            <identity>
                <userPrincipalName value="*******" />
            </identity>
        </endpoint>
    </client>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小梨窩很甜 2024-12-03 10:17:48

您是否考虑过在 SSIS 中使用类似的方法来读取 App.config 文件并解析 XML 文档以在 SSIS 包中设置变量?

http://www.sqlservercentral.com/articles/Integration+Services+(SSIS )/69550/

Have you looked at using something like this approach within SSIS to read the App.config file and parse the XML doc to set variables in the SSIS package?

http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/69550/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文