.NET 服务参考 - Soap 客户端状态始终为故障

.NET Service Reference - Soap Client state always Faulted

我有一个 .NET Web 表单应用程序,它使用 soap Web 服务进行某些操作。在我的解决方案中,项目很少,其中一个负责肥皂操作。因此,我向该项目添加了服务参考。我的旧发布运行良好,但现在,我无法调用 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();
    }

我不知道到底是什么问题。现在,我的客户工作没有任何问题。