我试图连接到GP网络服务从C#应用程序创建销售订单。但当我尝试连接它是抛出异常如下。
The application encountered an unhandled system exception. Contact your system administrator for details.
下面是我的app.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="GPWebService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows"
proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true" algorithmSuite="Default"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://WSGP:48620/Dynamics/GPService/GPService"
binding="wsHttpBinding" bindingConfiguration="GPWebService"
contract="GPWebService.DynamicsGP" name="GPWebService">
<identity>
<userPrincipalName value="WSGP\Administrator" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
C#使用服务的代码
CompanyKey companyKey;
Context context;
SalesOrder salesOrder;
SalesDocumentTypeKey salesOrderType;
CustomerKey customerKey;
BatchKey batchKey;
SalesOrderLine salesOrderLine;
ItemKey orderedItem;
Quantity orderedAmount;
Policy salesOrderCreatePolicy;
// Create an instance of the service
DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
// Create a context with which to call the service
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.UserName = "admin";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Password = "pass";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Domain = "WSGP";
System.ServiceModel.WSHttpBinding binding;
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);
//wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Domain = "wsgp";
context = new Context();
// Specify which company to use (sample company)
companyKey = new CompanyKey();
companyKey.Id = (-1);
// Set up the context object
context.OrganizationKey = (OrganizationKey)companyKey;
// Create a sales order object
salesOrder = new SalesOrder();
// Create a sales document type key for the sales order
salesOrderType = new SalesDocumentTypeKey();
salesOrderType.Type = SalesDocumentType.Order;
// Populate the document type key of the sales order object
salesOrder.DocumentTypeKey = salesOrderType;
// Create a customer key
customerKey = new CustomerKey();
customerKey.Id = "121001";
// Set the customer key property of the sales order object
salesOrder.CustomerKey = customerKey;
// Create a batch key
batchKey = new BatchKey();
batchKey.Id = "RMS";
// Set the batch key property of the sales order object
salesOrder.BatchKey = batchKey;
// Create a sales order line to specify the ordered item
salesOrderLine = new SalesOrderLine();
// Create an item key
orderedItem = new ItemKey();
orderedItem.Id = "8011172009618";
// Set the item key property of the sales order line object
salesOrderLine.ItemKey = orderedItem;
// Create a sales order quantity object
orderedAmount = new Quantity();
orderedAmount.Value = 4;
// Set the quantity of the sales order line object
salesOrderLine.Quantity = orderedAmount;
// Create an array of sales order lines
// Initialize the array with sales order line object
SalesOrderLine[] orders = { salesOrderLine };
// Add the sales order line array to the sales order
salesOrder.Lines = orders;
// Get the create policy for the sales order object
salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context);
// Create the sales order
wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);
// Close the service
if (wsDynamicsGP.State != CommunicationState.Faulted)
{
wsDynamicsGP.Close();
}
GP配置文件如下
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="cachingConfiguration" type="Microsoft.Dynamics.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Dynamics.EnterpriseLibrary.Caching, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<cachingConfiguration configSource="WSCachingConfiguration.config"/>
<appSettings file="WSServiceAppSettings.config">
<add key="SecurityRuntimeAuditQueuing" value="0"/>
<add key="SecurityRuntimeAuditingIsActive" value="false"/>
</appSettings>
<system.serviceModel>
<bindings configSource="WSBindings.config"/>
<services>
<service name="Microsoft.Dynamics.GP.WebServices.Contract.DynamicsGP" behaviorConfiguration="GPWCFStaticMetadataBehavior">
<endpoint address="Mex" name="http" binding="customBinding" bindingConfiguration="CustomBinding" contract="IMetadataExchange"/>
<endpoint address="GPService" name="GPWebService" binding="wsHttpBinding" bindingConfiguration="WSHttpBindingTarget" contract="Microsoft.Dynamics.GP.WebServices.Contract.IGPServices"/>
<host>
<baseAddresses>
<add baseAddress="http://WSGP:48620/Dynamics/GPService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="GPWCFStaticMetadataBehavior">
<serviceThrottling maxConcurrentSessions="1024"/>
<serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://WSGP:48620/Metadata/WCF/Full/schemas.microsoft.com.dynamics.gp.2010.01.wsdl"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceCredentials>
<userNameAuthentication cacheLogonTokens="true"/>
</serviceCredentials>
</behavior>
<behavior name="GPDynamicMetadataBehavior">
<serviceThrottling maxConcurrentSessions="1024"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceCredentials>
<userNameAuthentication cacheLogonTokens="true"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<client/>
</system.serviceModel>
<system.diagnostics>
<switches>
<add name="ApplicationTraceSwitch" value="0"/>
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="dynamicsListener"/>
</listeners>
</trace>
<sources>
<source name="System.ServiceModel" switchValue="" propagateActivity="true">
<!--Values can be:http://msdn.microsoft.com/en-us/library/ms733025.aspx -->
<listeners>
<add name="wcfListener"/>
</listeners>
</source>
<source name="System.IO.Log">
<listeners>
<add name="wcfListener"/>
</listeners>
</source>
<source name="System.Runtime.Serialization">
<listeners>
<add name="wcfListener"/>
</listeners>
</source>
<source name="System.IdentityModel">
<listeners>
<add name="wcfListener"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="wcfListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\Program Files\Microsoft Dynamics\GPWebServices\Logs\Tracing\GPWebServices.svclog"/>
<add name="dynamicsListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Program Files\Microsoft Dynamics\GPWebServices\Logs\Tracing\GPWebServices.log"/>
</sharedListeners>
</system.diagnostics>
</configuration>
我做错了什么?我在配置文件中遗漏了什么吗?
我应该说,我是Web服务开发的新手。
2条答案
按热度按时间hfsqlsce1#
这是因为我传递了错误的公司ID,我从DynamicWebserviceExceptionConsole获得了异常详细信息。当我试图传递正确的公司ID时,这是有效的。
ryevplcw2#
对于此类错误,您需要转到Dynamics“Web Services Console”控制台。在那里您将能够看到该错误的详细信息。要打开它,请在此处找到它:
C:\ProgramData\Microsoft\Windows\开始菜单\程序\管理工具\Dynamics GP Web服务异常管理控制台
或
“C:\Program Files\Common Files\Microsoft shared\Microsoft Dynamics\ManagementConsole\DynamicsWebServicesExceptionsConsole.”