gpt4 book ai didi

如果调用时间超过 1 分钟,ServiceBus 上的 WCF 服务将失败

转载 作者:行者123 更新时间:2023-12-04 21:22:23 25 4
gpt4 key购买 nike

我有一个托管在 ServiceHost 对象中的 WCF 服务。 ServiceHost 是在 Azure 辅助角色的 OnStart 方法上创建的。这是代码:

        ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

Uri baseAddress = ServiceBusEnvironment.CreateServiceUri("http", "my_sb", "SimpleService");

host = new ServiceHost(typeof(SimpleService1.Service1), baseAddress);

BasicHttpRelayBinding binding = new BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode.None, RelayClientAuthenticationType.None);
binding.OpenTimeout = new TimeSpan(1, 1, 0);
binding.ReceiveTimeout = new TimeSpan(1, 10, 0);
binding.SendTimeout = new TimeSpan(1, 10, 0);
binding.MaxReceivedMessageSize = 73400320;
XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
readerQuotas.MaxArrayLength = 73400320;
binding.ReaderQuotas = readerQuotas;

TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();
sharedSecretServiceBusCredential.CredentialType = TransportClientCredentialType.SharedSecret;

sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName = "owner";
sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = "blablablabla==";


ContractDescription contractDescription = ContractDescription.GetContract(typeof(SimpleService1.IService1), typeof(SimpleService1.Service1));
ServiceEndpoint serviceEndPoint = new ServiceEndpoint(contractDescription);
serviceEndPoint.Address = new EndpointAddress(baseAddress);
serviceEndPoint.Binding = binding;

IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public);

serviceEndPoint.Behaviors.Add(serviceRegistrySettings);
serviceEndPoint.Behaviors.Add(sharedSecretServiceBusCredential);


host.Description.Endpoints.Add(serviceEndPoint);

try
{

host.Open();

}

catch (Exception ex)
{

Trace.WriteLine(ex.Message, "Error");

throw;

}

Trace.WriteLine("SimpleService1 running...");

客户端的绑定(bind)配置为:

        <basicHttpBinding>
<binding name="FileTransferBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="73400320">
<readerQuotas maxArrayLength="73400320"/>
<security mode="None"/>
</binding>
</basicHttpBinding>

<endpoint address="http://my_sb.servicebus.windows.net/simpleservice" binding="basicHttpBinding" bindingConfiguration="FileTransferBinding" contract="Service1reference.IService1" name="FileTransferBinding" behaviorConfiguration="sbBehavior"/>

问题是,如果对服务的一次调用花费的时间超过 1 分钟,客户端就会收到此异常:

The content type application/xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly

如果我将绑定(bind)更改为 netTcpRelayBinding,则一切正常。

最佳答案

这是因为如果连接空闲时间超过一分钟,Windows Azure 负载平衡器就会断开您的连接。

最好的选择是使用 WCF 回调。这将执行从服务器到客户端的调用,以使其知道长时间运行的操作已完成。有关如何执行此操作的更多信息,请查看此博客 [ WCF Callbacks

关于如果调用时间超过 1 分钟,ServiceBus 上的 WCF 服务将失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7271050/

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