背景: 最终,第三方将在一台服务器上安装软件,并与我在另一台服务器上的服务进行通信。这个第三方没有仿真/测试软件,所以他们给了我他们的.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消息被公开知晓,所以需要进行编辑。