簡體   English   中英

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

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

背景:最終,第三方將在將在不同服務器上與我的服務進行通信的服務器上安裝軟件。 這個第三方沒有仿真/測試軟件,因此他們給了我們他們的.wsdl並建議我使用SoapUI來測試他們對我的服務的通信方面。 我的服務是用VB編寫的自托管(不是在iis上),但如果你有代碼更改建議,它可以在C#中。

問題:我無法讓SoapUI成功將Soap編碼的xml消息發送到我的服務。 我想要的最終結果是讓我的斷點在我的WCFLibrary中的函數中出現,該WCFLibrary是從我的界面實現我的操作合同

更多信息:經過多次試驗和錯誤后,我認為我的端點配置正確。 這是我第一次與WCF合作,在我開始之前,我按照MSDN上的計算器入門教程。 當我運行該服務時,我可以發送消息並從SoapUi獲得有效的響應,但它沒有達到視覺工作室的斷點,這對我來說不是好兆頭。 在我的研究中,我看到人們建議使用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 /我的界面,如果有人認為它會有所幫助,但我不會,直到有人要求它。

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 :(未改變)

<?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,但正如我的評論(或參見此處 )所示,配置SoapUI以將其與帶有為WSHttpBinding配置的端點的WCF服務結合使用還有一些功能。

就調試WCF服務而言,如果您從調試器中托管的服務進行調試,則一旦請求成功處理 ,它就應該中斷。 我使用visual studio擴展來調試名為VSCommands的WCF服務,該服務具有輕松附加到IIS app worker實例的功能(如果您的WCF服務在本地IIS Express中托管)。

  1. 如果這是您的服務,那么您如何測試?
  2. 如果這是您自己的服務,那么您可以使用fiddler在測試期間捕獲成功的請求和響應,然后在SoapUI中復制您的請求響應標頭和正文。
  3. 如果這不是您的服務,是否有任何成功請求的文檔,或者您是否可以讓創建者向您發送成功的請求? 在任何情況下,Fiddler或Soupui都可用於重新創建請求的標題和正文。 我沒有嘗試用SoaupUI調用我的服務,因為我通常只是在我的解決方案中創建另一個項目進行測試並使用fiddler來捕獲流量,但我不明白為什么如果你使用localhost就無法點擊斷點。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM