简体   繁体   English

SoapUI / WCF自托管Web服务/和Fiddler

[英]SoapUI/ WCF Self-Hosted Webservices/ and Fiddler

Background: Eventually a third party will install software on a server that will be communicating with my service on a different server. 背景:最终,第三方将在将在不同服务器上与我的服务进行通信的服务器上安装软件。 This third party has no emulation/testing software so they have given me their .wsdl and suggested that I use SoapUI to test their side of communication against my service. 这个第三方没有仿真/测试软件,因此他们给了我们他们的.wsdl并建议我使用SoapUI来测试他们对我的服务的通信方面。 My service is a self-hosted (not on iis) written in VB but if you do have a code change suggestion it can be in C#. 我的服务是用VB编写的自托管(不是在iis上),但如果你有代码更改建议,它可以在C#中。

Issue: I cannot get SoapUI to successfully send Soap encoded xml messages to my service. 问题:我无法让SoapUI成功将Soap编码的xml消息发送到我的服务。 The end result I want is to have my breakpoint hit in my function in my WCFLibrary that is implementing my operation contract from my interface 我想要的最终结果是让我的断点在我的WCFLibrary中的函数中出现,该WCFLibrary是从我的界面实现我的操作合同

More Information: After much trial and error I think I have my endpoints configured correctly. 更多信息:经过多次试验和错误后,我认为我的端点配置正确。 This is my first venture with WCF and before I started i followed the getting started tutorial on MSDN for the calculator. 这是我第一次与WCF合作,在我开始之前,我按照MSDN上的计算器入门教程。 When I have that service running I can send a message and get a valid response from SoapUi but it doesn't hit the break point in visual studio which doesn't bode well for me. 当我运行该服务时,我可以发送消息并从SoapUi获得有效的响应,但它没有达到视觉工作室的断点,这对我来说不是好兆头。 In my research I saw that people suggest using Fiddler to help troubleshoot this issue. 在我的研究中,我看到人们建议使用Fiddler来帮助解决这个问题。 I was able to get this work but the error that i see in fiddler is basically the same thing I see in SoapUI 我能够得到这个工作,但我在fiddler中看到的错误与我在SoapUI中看到的基本相同

What I am trying to send to my service. 我想要发送给我的服务。

<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>

The Repsonse I am getting: 我得到的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>

What I am confused on: So the key part of this error message is the "The message could not be processed. This is most likely because the action ' Redacted is incorrect" Why would it be looking at Redacted for this Redacted action? 我很困惑上:所以这个错误消息的关键部分是“无法处理的消息,这是最有可能的,因为行动“ 编校不正确。”为什么会在看删节编校的行动? - That will be inplace eventually when the third party installs their software but my perception was SoapUI reads in the WSDL in order to know what actions to have and then doesn't use it anymore and just fires the Soap messages that I ask for at the endpoint that I am telling it to. - 当第三方安装他们的软件时,这将是最终的, 但我的感觉是SoapUI在WSDL中读取,以便知道有什么操作,然后不再使用它,只是触发我要求的Soap消息我告诉它的终点。 I am starting to think I am wrong about this then. 我开始认为我错了。 Also the only difference between the test service and my service is the content type. 此外,测试服务和我的服务之间的唯一区别是内容类型。 The test service has a content type of "text/xml; charset=utf-8" and mine is "application/soap+xml; charset=utf-8" 测试服务的内容类型为“text / xml; charset = utf-8”,我的是“application / soap + xml; charset = utf-8”

I have also tried: When I saw that error message I thought well maybe I need to make my a wsdl based on my service. 我也尝试过:当我看到错误信息时,我想也许我需要根据我的服务制作一个wsdl。 So I used the SDK tool to make a wsdl on my service and then imported it to SoapUI and pointed to the endpoint to my running service but the response I got was a 所以我使用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; HTTP / 1.1 415无法处理消息,因为内容类型'text / xml; charset = UTF-8'不是预期类型'application / soap + xml; charset=utf-8'. 字符集= UTF-8' 。 Content-Length: 0 Server: Microsoft-HTTPAPI/2.0 Date: Fri, 03 Jan 2014 14:00:25 GMT 内容长度:0服务器:Microsoft-HTTPAPI / 2。0日期:2014年1月3日星期五14:00:25 GMT

Then I gave up goin down this path. 然后我放弃了走这条路。

Last Thing: Even if I am able to get this to work, will this still not hit my breakpoint in my service that is running? 最后的事情:即使我能够让它工作,这仍然不会在我正在运行的服务中遇到断点吗? I ask this because like I said earlier, in the test wcf service that I made it didn't hit the break point when it gave me back a valid response. 我问这个是因为就像我之前说过的那样,在我测试的wcf服务中,当它给我一个有效的响应时它没有达到断点。

Here is the message / Valid response I am getting for the working test service 这是我为工作测试服务获得的消息/有效响应

Send: 发送:

<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>

Receive: 接收:

<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>

I can post my App.config / My interface if anyone think it will help but I won't until someone asks for it. 我可以发布我的App.config /我的界面,如果有人认为它会有所帮助,但我不会,直到有人要求它。

App.Config for my WebService: (Altered and I commented out the original) App.Config for my WebService :(改了,我注释掉了原文)

<?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 for my (Host) Service: (Unaltered) App.Config for my(Host)Service :(未改变)

<?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>

My client will be SoapUI - So I don't have a client service / client App.Config 我的客户端将是SoapUI - 所以我没有客户端服务/客户端App.Config

EDIT I am now getting to the point where my soap message will bounce off my service and get rejected because it cannot deserialize it. 编辑我现在已经到了我的肥皂消息将从我的服务中反弹并被拒绝的程度,因为它无法反序列化它。

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)

Edit Because the Third Party did not want their XML message to be made public knowledge 编辑因为第三方不希望他们的XML消息成为公共知识

This is likely a configuration problem. 这可能是配置问题。 The error message indicates a difference in version of SOAP. 错误消息指示SOAP版本的差异。 The most likely problem is that your server is using WSHttpBinding in it's endpoint configuration and your client is configured to use BasicHttpBinding. 最可能的问题是您的服务器在其端点配置中使用WSHttpBinding,并且您的客户端配置为使用BasicHttpBinding。

If that is the case, you can solve your problem by properly configuring a WSHttpBinding for your client endpoint. 如果是这种情况,您可以通过为客户端端点正确配置WSHttpBinding来解决问题。 It looks like you've already changed your endpoint configuration to exclude BasicHttpBinding, but that could be an alternative solution. 看起来您已经更改了端点配置以排除BasicHttpBinding,但这可能是一种替代解决方案。

I'm not familiar with SoapUI, but as indicated in my comment (or see here ) there is a little more to configuring SoapUI to use it in conjunction with a WCF service with an endpoint configured for WSHttpBinding. 我不熟悉SoapUI,但正如我的评论(或参见此处 )所示,配置SoapUI以将其与带有为WSHttpBinding配置的端点的WCF服务结合使用还有一些功能。

As far as debugging a WCF service, if you are hitting it from a service hosted in your debugger, it should be breaking once the request is successfully processed . 就调试WCF服务而言,如果您从调试器中托管的服务进行调试,则一旦请求成功处理 ,它就应该中断。 I use a visual studio extension for debugging WCF services called VSCommands which has a feature for easily attaching to IIS app worker instances (if your WCF service is being hosted in IIS express locally.) 我使用visual studio扩展来调试名为VSCommands的WCF服务,该服务具有轻松附加到IIS app worker实例的功能(如果您的WCF服务在本地IIS Express中托管)。

  1. If this is your service then how are you testing? 如果这是您的服务,那么您如何测试?
  2. If this is your own service then you can use fiddler to catch the successful request and response during your test and then duplicate your request the response header and body in SoapUI. 如果这是您自己的服务,那么您可以使用fiddler在测试期间捕获成功的请求和响应,然后在SoapUI中复制您的请求响应标头和正文。
  3. If this is not your service is there any documentation with a successful request or can you have the creator send you a successful request? 如果这不是您的服务,是否有任何成功请求的文档,或者您是否可以让创建者向您发送成功的请求? In any case Fiddler or Soupui can be used to recreate the header and body of the request. 在任何情况下,Fiddler或Soupui都可用于重新创建请求的标题和正文。 I have not attempted to call my service with SoaupUI because i would normally just create another project in my solution for testing and use fiddler to capture traffic, but i don't see why you couldn't hit you breakpoints if your using localhost. 我没有尝试用SoaupUI调用我的服务,因为我通常只是在我的解决方案中创建另一个项目进行测试并使用fiddler来捕获流量,但我不明白为什么如果你使用localhost就无法点击断点。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM