我有一个.NET Web窗体应用程序,它使用soap Web服务进行某些操作。在我的解决方案中,项目很少,其中一个项目负责肥皂业务。因此,我向该项目添加了Service Reference。我的旧发布效果很好,但现在,由于抛出错误,我无法在Web服务中调用任何方法。
错误消息:
The communication object, System.ServiceModel.ChannelFactory`1[ProjectName.IntegrationServiceSoap], cannot be used for communication because it is in the Faulted state.
[每当创建一个soap客户端实例时,它的state
属性始终为Faulted
。
我使用测试端点对其进行了测试,已删除并重新添加了服务引用,但是它不起作用。
堆栈跟踪:
at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposed()
at System.ServiceModel.ChannelFactory.EnsureOpened()
at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.ChannelFactory`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannelInternal()
at System.ServiceModel.ClientBase`1.get_Channel()
at SoapLibrary.IntegrationServiceSoapClient.ProjectName.IntegrationServiceSoap.GetTicket(TicketRequest request) in C:\Users\...
这是我的配置文件
主项目Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation targetFramework="4.5.1" debug="true" />
<!--Including other configs-->
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IntegrationServiceSoap" maxReceivedMessageSize="2147483647" sendTimeout="23:59:59" receiveTimeout="23:59:59" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://mywebservice.com/IntegrationService.asmx"
binding="basicHttpBinding" bindingConfiguration="IntegrationServiceSoap"
contract="MyService.IntegrationServiceSoap" name="IntegrationServiceSoap" />
</client>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
第二个项目(包括肥皂服务参考)App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IntegrationServiceSoap" receiveTimeout="23:59:59"
sendTimeout="23:59:59" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://mywebservice.com/IntegrationService.asmx"
binding="basicHttpBinding" bindingConfiguration="IntegrationServiceSoap"
contract="MyService.IntegrationServiceSoap" name="IntegrationServiceSoap" />
</client>
</system.serviceModel>
</configuration>
有什么想法吗?如何解决此问题?
我通过将项目的.NET Framework版本从4.5.1
降级为4.5
解决了该问题>
我还向我的SoapClient添加了故障侦听器。
private void CreateSoapClient() { client = new IntegrationServiceSoapClient("IntegrationServiceSoap"); client.ChannelFactory.Faulted += ChannelFactory_Faulted; } private void ChannelFactory_Faulted(object sender, EventArgs e) { client.Abort(); client.ChannelFactory.Faulted -= ChannelFactory_Faulted; client = null; CreateSoapClient(); }
我不知道实际上是什么问题。现在,我的客户可以正常工作了。