在Windows控制台应用程序中使用ax2012服务

4

我有一台安装了AX2012的远程机器,在其中我已经在AX2012中构建了一个自定义服务,并且我能够在Windows控制台应用程序(VS2010)中正常使用它。但是当我尝试通过Windows控制台应用程序(VS2012)从自己的机器连接到服务时,它会给出错误“服务器拒绝客户端凭据。”

我的代码如下:

 ServiceReference1.TestService1Client t = new ServiceReference1.TestService1Client();
        t.ClientCredentials.UserName.UserName = "vanya";
        t.ClientCredentials.UserName.Password = "*******";
        t.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
        ServiceReference1.CallContext c = new ServiceReference1.CallContext();
        c.Company = "ussi";
        ServiceReference1.EventList eventss = t.getEventItems(c, "BradPSUS", "contoso.com");

我的app.config文件中的绑定如下所示:
 <bindings>
        <netTcpBinding>
          <binding name="NetTcpBinding_TestService1" transferMode="Buffered" />

            <binding name="NetTcpBinding_ItemService" />
        </netTcpBinding>
    </bindings>

如果我在app.config中添加security mode = "none",就会出现以下错误:“套接字连接中止。这可能是由于处理您的消息或远程主机超时接收超时引起的错误,或底层网络资源问题。本地套接字超时为“00:00:59.9609696”“。
相同的方法在远程设备上完美运行,但在我的设备上却无法工作。我该怎么做?

远程机器是否在内部网络上运行?这个网络和本地机器的网络一样吗?我没有AX 2012的经验,但是考虑到当您将安全模式设置为无时收到的错误消息以及它在远程工作的事实,可能存在不匹配的子网。 - James Wright
远程机器在不同的域上。 - Vanya
1个回答

1

经过一周的寻找,我终于找到了解决方案。在此分享答案,以帮助可能会在未来遇到此问题的其他人:

  1. 将服务的适配器从Net.Tcp更改为HTTP
  2. 通过进入AX->入站端口->配置更改服务绑定的安全详细信息。 enter image description here
  3. 在IIS中托管服务,如果要从其他域使用它,则必须在IIS上托管服务。此链接说明了该过程 http://technet.microsoft.com/en-us/library/gg731848.aspx
  4. 仅在IIS上启用Windows身份验证。 enter image description here
  5. 在与AX安装在同一台计算机上的Visual Studio中创建控制台应用程序。添加对服务的引用。您的app.config应如下所示:
        <?xml version="1.0" encoding="utf-8" ?>
        <configuration>
         <system.serviceModel>     
          <bindings>
          <basicHttpBinding>
             <binding name="BasicHttpBinding_Service1" allowCookies="true"
          maxBufferPoolSize="20000000" maxBufferSize="20000000" maxReceivedMessageSize="20000000">
    
        <readerQuotas maxDepth="32" maxStringContentLength="200000000"
            maxArrayLength="200000000" />
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Windows" />
        </security>
      </binding>
    </basicHttpBinding>
        </bindings>
               <client>          
           <endpoint address="http://******/MicrosoftDynamicsAXAif60/Test3/xppservice.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service1"
          contract="ServiceReference1.Service1" name="BasicHttpBinding_Service1" >           
      </endpoint>
    </client>
      </system.serviceModel>
        </configuration>
  6. 将此控制台应用程序的dll复制到其他机器上(不在同一域中的机器)
  7. 创建控制台应用程序并引用此dll。使用此dll访问服务。
  8. 粘贴相同的app.config内容。
  9. 在.cs文件中添加以下三行代码:
        workListSvc.ClientCredentials.Windows.ClientCredential.Domain = "*****";
        workListSvc.ClientCredentials.Windows.ClientCredential.UserName = "kevin";
        workListSvc.ClientCredentials.Windows.ClientCredential.Password = "*****";
  10. 现在应该可以工作了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接