加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 21:51:03 所属栏目:百科 来源:网络整理
导读:我有一台安装了AX2012的远程计算机,在其中我已经在AX2012中构建了一个自定义服务,我可以在 Windows控制台应用程序(VS2010)中正确使用它.但是,当我尝试通过Windows控制台应用程序(VS2012)从我自己的计算机连接到服务时,它给出了错误“服务器已拒绝客户端凭据
我有一台安装了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中添加安全模式=“无”,我会收到以下错误“套接字连接已中止.这可能是由于处理消息时出错或远程主机超出接收超时或基础网络资源问题.本地套接字超时为’00:00:59.9609696’“

同样的事情在远程机器上完美运行但在我的机器上不起作用.我该怎么办?

解决方法

一周后我找到了解决方案.添加答案以帮助将来可能面临此问题的其他人:

>将服务的适配器从Net.Tcp更改为HTTP
>转到AX-> Inbound Port-> Configure,更改服务绑定的安全性详细信息.

>在IIS中托管服务,如果要从其他域使用服务,则必须在IIS上托管服务.此链接说明了流程http://technet.microsoft.com/en-us/library/gg731848.aspx
>仅在IIS上启用Windows身份验证.

>在Visual Studio上安装AX的同一台机器上创建一个控制台应用程序.添加对服务的引用.您的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>

>获取此控制台应用程序的DLL并将其粘贴到您的其他计算机(不在同一域中的计算机)上
>创建一个控制台应用程序并添加对此dll的引用.使用此dll访问该服务.
>粘贴相同的app.config内容.
>在.cs文件中添加这三行

workListSvc.ClientCredentials.Windows.ClientCredential.Domain = "*****";
    workListSvc.ClientCredentials.Windows.ClientCredential.UserName = "kevin";
    workListSvc.ClientCredentials.Windows.ClientCredential.Password = "*****";

>现在应该工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读