问题:我无法让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>
我对此感到困惑:因此,此错误消息的关键部分是“无法处理消息.这很可能是因为”已编辑的操作不正确“
为什么要查看Redacted以获取此Redated操作? – 当第三方安装他们的软件时,这将是最终的,但我的感觉是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,但正如我的评论(或参见here)所示,配置SoapUI以将其与具有为WSHttpBinding配置的端点的WCF服务结合使用还有一些更多.
就调试WCF服务而言,如果您从调试器中托管的服务进行调试,则一旦请求成功处理,它就应该中断.我使用visual studio扩展来调试名为VSCommands的WCF服务,该服务具有轻松附加到IIS app worker实例的功能(如果您的WCF服务在本地IIS Express中托管).