简体   繁体   中英

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

Issue: I cannot get SoapUI to successfully send Soap encoded xml messages to my service. 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

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. 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. In my research I saw that people suggest using Fiddler to help troubleshoot this issue. I was able to get this work but the error that i see in fiddler is basically the same thing I see in 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:

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

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

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

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.

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 for my WebService: (Altered and I commented out the original)

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

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

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

This is likely a configuration problem. The error message indicates a difference in version of 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.

If that is the case, you can solve your problem by properly configuring a WSHttpBinding for your client endpoint. It looks like you've already changed your endpoint configuration to exclude BasicHttpBinding, but that could be an alternative solution.

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.

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

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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