SoapUI/ WCF 自托管网络服务/ 以及 Fiddler

4

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

问题: 我无法让SoapUI成功发送SOAP编码的XML消息到我的服务端。我想要的最终结果是在实现我的接口中操作合同的WCFLibrary函数中打断点。

更多信息: 经过多次尝试和错误,我认为我的端点已经配置正确。这是我第一次尝试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>

我收到的响应:
<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>

我困惑的是:这个错误信息关键部分是"The message could not be processed. This is most likely because the action 'Redacted' is incorrect",为什么会查找'Redacted'这个动作?- 当第三方安装他们的软件时,它最终会被放置在那里,但是我的看法是SoapUI读取WSDL以了解应该有哪些操作,然后不再使用它,只向我告诉它的端点发送我要求的 Soap 消息。我开始认为我对此错了。另外,测试服务和我的服务之间唯一的区别是内容类型。测试服务的内容类型为"text / xml; charset = utf-8",而我的内容类型为"application / soap + xml; charset = utf-8"
我还尝试过:当我看到那个错误消息时,我想也许我需要根据我的服务创建一个基于 wsdl 的服务。所以我使用 SDK 工具在我的服务上创建了一个 wsdl,然后将其导入到 SoapUI 中,并指向正在运行的服务的端点,但我得到的响应是 HTTP/1.1 415 Cannot process the message because the content type 'text/xml;charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'. Content-Length: 0 Server: Microsoft-HTTPAPI/2.0 Date: Fri, 03 Jan 2014 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

编辑现在我已经到了这个点,我的soap消息将被我的服务反弹并被拒绝,因为它无法反序列化。

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消息被公开知晓,所以需要进行编辑。


1
在您的SoapUI配置中,您是否按照此处概述的步骤进行操作?http://social.msdn.microsoft.com/Forums/vstudio/en-US/85301e19-655c-409f-8ac6-599c6944910c/wcf-wshttpbinding-soap-12-not-working-with-soapui-tool?forum=wcf - Todd Richardson
我尝试从我的App.Config中的端点配置中删除身份验证部分,但似乎没有任何作用。请参见我的编辑以获取更多信息。 - Brandon
我正在研究这个问题,并在SO上找到了您的另一个问题,我想知道:您是否在通过SoapUI调用服务时遇到了所有调用的问题,还是只有在调用orderstatus时出现了问题?否则,我认为这个错误是因为您的orderstatus没有定义命名空间。您可以通过序列化程序来解决这个问题。 - Todd Richardson
2个回答

3
这很可能是一个配置问题。错误消息表示SOAP版本存在差异。最可能的问题是你的服务器在它的端点配置中正在使用WSHttpBinding,而你的客户端配置为使用BasicHttpBinding。
如果是这种情况,您可以通过为客户端端点正确配置WSHttpBinding来解决问题。看起来你已经改变了你的端点配置以排除BasicHttpBinding,但这可能是一种替代的解决方案。
我不熟悉SoapUI,但正如我的评论所示(或见此处),配置SoapUI与配置为WSHttpBinding的WCF服务一起使用还需些许注意。
至于调试WCF服务,如果你从调试器中托管的服务中访问它,它应该会在请求成功处理后暂停。我使用一个名为VSCommands的Visual Studio扩展程序来调试WCF服务,其具有轻松附加到IIS应用程序工作实例的功能(如果您的WCF服务在本地使用IIS express托管)。

感谢你的帮助,Todd。给你一个赞,我会在这个问题解决后给你悬赏的。但是看起来我的 Soap Action 不正确。我不确定它应该是什么,我已经尝试使用了 "http://localhost:8000/ServiceModelSamples/Service/PassUnsolicitedMessage" 和 "http://localhost:8000/UnsolicitedListenerLib/Service1/PassUnsolicitedMessage",但都没有成功。 - Brandon

0
  1. 如果这是您的服务,那么您是如何进行测试的?
  2. 如果这是您自己的服务,您可以使用Fiddler在测试期间捕获成功的请求和响应,然后在SoapUI中复制您的请求、响应头和正文。
  3. 如果这不是您的服务,是否有任何成功请求的文档或者您可以让创建者发送一个成功的请求?无论如何,Fiddler或Soupui都可以用来重新创建请求的头和正文。我没有尝试使用SoaupUI调用我的服务,因为我通常会在我的解决方案中创建另一个项目进行测试,并使用Fiddler来捕获流量,但如果您使用localhost,我认为您也可以命中断点。

希望这能帮到您。


是的,我正在测试的服务是我正在编写的服务。我正在尝试使用SoapUi来测试它,以替代我无法访问的第三方软件,直到上线。SoapUi将向我在本地机器上托管的服务发送soap消息(处于开发阶段)。 - Brandon
你是否试图复制将发送到你的服务的期望请求? - dtucker1914
是的,我正在使用重复请求。我认为消息本身没有任何问题,但您认为这是我应该研究的问题吗? - Brandon
是的,捕获消息并将其与文档或示例调用进行比较(如果有)。 - dtucker1914

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接