gpt4 book ai didi

c# - Microsoft ServiceBus - 参数实体名称为 null 或为空

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:49 24 4
gpt4 key购买 nike

我使用 Servicebus 作为 Web 应用程序和 BizTalk 之间的链接。在网络应用程序中,我之前在 web.config 中定义了整个端点,但端点必须是动态的,因此我尝试通过代码设置端点。

更改后,当我尝试向队列发送消息时,我只会收到异常。 (ArgumentException - 参数实体名称为 null 或为空)

以下是将消息发送到队列的代码:

string queuename = Company.GetQueueName(O.companyId);
var factory = new ChannelFactory<IOrder>("requestQueueClientEndpoint", new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("sb", queuename, string.Empty)));
var OrdRspChannel = factory.CreateChannel();

OrdRspChannel.Order(O);

这是配置:

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="securityBehavior">
<TransportClientEndpointBehavior>
<tokenProvider>
<sharedSecret issuerName="owner" issuerSecret="SECRET REMOVED" />
<serviceCertificate>
<authentication revocationMode="NoCheck"/>
</serviceCertificate>
</tokenProvider>
</TransportClientEndpointBehavior>
</behavior>
</endpointBehaviors>
</behaviors>

<bindings>
<netMessagingBinding>
<binding name="netMessagingBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00" sessionIdleTimeout="00:10:00" prefetchCount="-1">
<transportSettings batchFlushInterval="00:00:01" />
</binding>
</netMessagingBinding>
</bindings>

<client>
<!-- Invoke BizTalk via Service Bus Queue -->
<endpoint address="ADDRESS REMOVED" behaviorConfiguration="securityBehavior" binding="netMessagingBinding" bindingConfiguration="netMessagingBinding" contract="Procurement_MVC3.IOrder" name="requestQueueClientEndpoint" />
</client>
</system.serviceModel>

这是堆栈跟踪:

{System.ArgumentException: The argument entityName is null or empty.
Parameter name: entityName

Server stack trace:
at Microsoft.ServiceBus.Messaging.MessagingFactory.CheckValidEntityName(String entityName, Int32 maxEntityNameLength, Boolean allowSeparator, String paramName)
at Microsoft.ServiceBus.Messaging.MessagingFactory.<>c__DisplayClass1d.<BeginCreateMessageSender>b__1b(AsyncCallback c, Object s)
at Microsoft.ServiceBus.Messaging.OpenOnceManager.OpenOnceManagerAsyncResult`1.BeginOpenCompleted(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.OpenOnceManager.OpenOnceManagerAsyncResult`1.BeginOpen()
at Microsoft.ServiceBus.Messaging.OpenOnceManager.OpenOnceManagerAsyncResult`1..ctor(OpenOnceManager openOnceManager, TimeSpan openTimeout, AsyncCallback callback, Object state, Func`3 beginOperation, EndOperation`1 endOperation)
at Microsoft.ServiceBus.Messaging.OpenOnceManager.Begin[T](AsyncCallback callback, Object state, Func`3 beginOperation, Func`2 endOperation)
at Microsoft.ServiceBus.Messaging.MessagingFactory.BeginCreateMessageSender(String entityPath, TimeSpan timeout, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.Channels.ServiceBusOutputChannel.OpenMessagingFactoryAndMessageSenderAsyncResult.CreateFactoryComplete(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.Channels.ServiceBusOutputChannel.OpenMessagingFactoryAndMessageSenderAsyncResult..ctor(ServiceBusOutputChannel outputChannel, TimeSpan timeout, AsyncCallback callback, Object state)
at Microsoft.ServiceBus.Messaging.Channels.ServiceBusOutputChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Procurement_MVC3.IOrder.Order(Order Order)
at Procurement_MVC3.Controllers.HomeController.ViewOrder(String id, Nullable`1 date, Nullable`1 confirmqty, String orderrowid, String supplierorderId, Boolean confirm) in c:\Projects2\trunk\Procurement_MVC3\Procurement_MVC3\Controllers\HomeController.cs:line 229}

我在 Google 和 StackOverflow 上搜索了类似的场景,但一无所获。我还必须使用此代码更新生产环境,这是拼图的最后一 block ,因此它开始拖延。

最佳答案

ServiceBusEnvironment.CreateServiceUri API 采用三个参数:协议(protocol)、命名空间和服务路径(对于您正在使用的绑定(bind),映射到队列名称)。在您提供的示例中,您将队列名称作为命名空间传递,并且缺少实体名称,从而导致缺少实体名称异常。

尝试将您的代码片段切换为如下所示:

var factory = new ChannelFactory<IOrder>("requestQueueClientEndpoint", new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("sb", namespaceName, queuename)));

关于c# - Microsoft ServiceBus - 参数实体名称为 null 或为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12896570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com