.net - SoapUI/WCF 自托管 Web 服务/和 Fiddler

标签 .net wcf web-services soapui

背景:最终,第三方将在服务器上安装软件,该软件将与我在另一台服务器上的服务进行通信。这个第三方没有模拟/测试软件,所以他们给了我他们的 .wsdl 并建议我使用 SoapUI 来测试他们针对我的服务的通信方面。我的服务是用 VB 编写的自托管(不在 iis 上),但如果您确实有代码更改建议,则可以使用 C#。

问题:我无法让 SoapUI 成功地将 Soap 编码的 xml 消息发送到我的服务。我想要的最终结果是在我的 WCFLibrary 中的函数中设置断点,该函数正在从我的界面实现我的操作契约(Contract)

更多信息:经过多次反复试验,我认为我的端点配置正确。这是我第一次使用 WCF,在我开始之前,我遵循了 MSDN 上的计算器入门教程。当我运行该服务时,我可以发送消息并从 SoapUi 获得有效响应,但它没有在 Visual Studio 中达到断点,这对我来说不是好兆头。在我的研究中,我看到人们建议使用 Fiddler 来帮助解决此问题。我能够完成这项工作,但我在 fiddler 中看到的错误与我在 SoapUI 中看到的基本相同

我想发送给我的服务的内容。

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
    <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <wsa:Action>**Redacted**</wsa:Action>
        <wsa:To>http://localhost:8000/UnsolicitedListenerLib/Service1</wsa:To>
    </soap:Header>
    <soap:Body>
        <tem:**Redacted**/>
    </soap:Body>
</soap:Envelope>

我得到的 Repsonse:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
    </s:Header>
    <s:Body>
        <s:Fault>
            <s:Code>
                <s:Value>s:Sender</s:Value>
                <s:Subcode>
                    <s:Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value>
                </s:Subcode>
            </s:Code>
            <s:Reason>
                <s:Text xml:lang="en-US">The message could not be processed. This is most likely because the action **Redacted** is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.</s:Text>
            </s:Reason>
        </s:Fault>
    </s:Body>
</s:Envelope>

我对什么感到困惑:因此,此错误消息的关键部分是“无法处理消息。这很可能是因为操作' 已编辑 不正确”
为什么会看已编辑 为此 已编辑 行动? - 最终当第三方安装他们的软件时,这将就位,但我的看法是 SoapUI 读取 WSDL 以便知道要执行哪些操作,然后不再使用它,只是触发我要求的 Soap 消息我告诉它的端点。那时我开始认为我错了。测试服务和我的服务之间的唯一区别是内容类型。测试服务的内容类型为“text/xml; charset=utf-8”,我的是“application/soap+xml; charset=utf-8”

我也试过:当我看到那个错误消息时,我想可能我需要根据我的服务制作一个 wsdl。因此,我使用 SDK 工具在我的服务上创建了 wsdl,然后将其导入 SoapUI 并指向我正在运行的服务的端点,但我得到的响应是

HTTP/1.1 415 无法处理消息,因为内容类型 'text/xml;charset=UTF-8' 不是预期的类型 'application/soap+xml;字符集=utf-8'。
内容长度:0
服务器:Microsoft-HTTPAPI/2.0
日期:2014 年 1 月 3 日星期五 14:00:25 GMT

然后我放弃了沿着这条路走下去。

最后一件事:即使我能够让它工作,这仍然不会在我正在运行的服务中达到我的断点吗?我问这个是因为就像我之前说的,在我制作的测试 wcf 服务中,当它给我一个有效的响应时,它没有达到断点。

这是我为工作测试服务收到的消息/有效响应

发送:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mic="http://Microsoft.ServiceModel.Samples">
   <soapenv:Header/>
   <soapenv:Body>
      <mic:Add/>
   </soapenv:Body>
</soapenv:Envelope>

收到:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <AddResponse xmlns="http://Microsoft.ServiceModel.Samples">
            <AddResult>0</AddResult>
        </AddResponse>
    </s:Body>
</s:Envelope>

如果有人认为它会有所帮助,我可以发布我的 App.config/我的界面,但在有人要求之前我不会发布。

我的 WebService 的 App.Config:(已更改,我注释掉了原来的)
<?xml version="1.0"?>
<configuration>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource"
              switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch"
           value="Information"/>
    </switches>
    <sharedListeners>
      <add name="FileLog"
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
           initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/><serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingNoSecurity">
          <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
          </security>
            </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="UnsolicitedListenerLib.Service1" behaviorConfiguration="Service1Behavior">
        <host>
          <baseAddresses>
            <!--<add baseAddress="http://localhost:8732/Design_Time_Addresses/UnsolicitedListenerLib/Service1/"/>-->
            <add baseAddress="http://localhost:8000/UnsolicitedListenerLib/Service1"/>
          </baseAddresses>
        </host>
        <!--<endpoint address="" binding="basicHttpBinding" contract="UnsolicitedListenerLib.UnsolictedListenerService.IService1">-->
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingNoSecurity" contract="UnsolicitedListenerLib.UnsolictedListenerService.IService1">
           <identity><dns value="localhost"/></identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"/>
      </service>
    </services>  
  </system.serviceModel>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

我的(主机)服务的 App.Config:(未更改)
<?xml version="1.0"?>
<configuration>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information"/>
        </switches>
        <sharedListeners>
            <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

我的客户端将是 SoapUI - 所以我没有客户端服务/客户端 App.Config

编辑
我现在已经到了我的肥皂消息会从我的服务中反弹并被拒绝的地步,因为它无法反序列化它。
Raw Fiddler Headers
POST /UnsolicitedListenerLib/Service1 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://tempuri.org/IService1/orderstatus"
Content-Length: 890
Host: localhost:8000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

编辑因为第三方不希望他们的 XML 消息被公开

最佳答案

这很可能是配置问题。错误消息表明 SOAP 的版本不同。最可能的问题是您的服务器在其端点配置中使用 WSHttpBinding,而您的客户端配置为使用 BasicHttpBinding。

如果是这种情况,您可以通过为客户端端点正确配置 WSHttpBinding 来解决问题。看起来您已经更改了端点配置以排除 BasicHttpBinding,但这可能是一种替代解决方案。

我不熟悉 SoapUI,但正如我的评论(或参见 here )中所指出的,配置 SoapUI 以将其与 WCF 服务结合使用,并为 WSHttpBinding 配置端点,还需要做更多的工作。

就调试 WCF 服务而言,如果您从调试器中托管的服务中访问它,则在成功处理请求后它应该会中断。我使用 Visual Studio 扩展来调试名为 VSCommands 的 WCF 服务,它具有轻松附加到 IIS 应用程序工作器实例的功能(如果您的 WCF 服务托管在本地 IIS express 中。)

关于.net - SoapUI/WCF 自托管 Web 服务/和 Fiddler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20906588/

相关文章:

wcf - 使用 Windsor 创建 WCF 服务时出现问题

wcf - 我的 IIS 托管 wcf 服务在什么用户帐户下运行?

c# - 如何通过 [WebMethod] 返回数据表

c# - ReaderWriterLockSlim 是否有等效的 lock{} 语句?

c# - 使用 JSON.NET 将已知和未知的 JSON 字段反序列化为 CLR 对象

c# - 无法通过类库使用WCF服务客户端

c# - 客户端发现响应内容类型为 "but expected ' text/xml' 请求失败,响应为空

java - 无法从某些 wsdl 生成 java 客户端代码

c# - 如何从 C# WinForms 应用程序判断 SQL Server 自动升级是否成功

c# - 为什么 (object)0 == (object)0 不同于 ((object)0).Equals((object)0)?