WF4 - 如何使用外部Web服务?
我很难找到明确引导您设置可调用外部 Web 服务的 WF4 工作流活动的资源或在线教程。我遇到的所有视频和在线示例都只是演示了如何使用属于 Visual Studio 解决方案一部分的 Web 服务,但我的情况需要调用非 Microsoft 服务器上的 Web 服务。
我在 VS2010 工作流控制台项目中添加了相关 Web 服务的服务引用,它指向外部 Web 服务的 WSDL。到目前为止,一切都很好(我认为)。我有一个非常基本的工作流程序列,使用 SendAndReceiveReply 工作流程控件与外部服务器进行通信,并且我相信我已正确配置 Send 部分。但是,ReceiveReplyForSend 给我带来了麻烦,并且我不确定其Content 选项是否设置正确。我正在调用一个名为 FileCheck 的操作,目前出于测试目的,该操作始终返回值 1,如下所示:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<FileCheckResponse>
<FileCheckResult>1</FileCheckResult>
</FileCheckResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但是,如果我尝试运行此操作,则会收到错误“格式错误的 SOAP 消息” ”。就其价值而言,我的 ReceiveReplyForSend 设置了一个名为 FileCheckResult 的参数,尽管我不知道这是否是获取上述值的正确方法。
我可以在任一活动中放置一个断点,但我不知道如何查看此时的 SOAP 调用是什么样子的。有人可以给我一些工作流程发送/回复调试技巧,或者为我指明如何在 WF4 中使用外部 Web 服务的优秀分步教程吗?
2011 年 2 月 2 日更新:感谢 Maurice 的建议,我现在清楚地看到了问题所在。我的工作流程中的 Web 服务调用失败,因为 Visual Studio 在我的工作流程 Send 调用中生成了对错误命名空间的引用。以下是 SOAP 消息中错误的 XML 位 - 为了简洁起见,我将省略 SOAP 信封的其余部分:
<FileCheck xmlns="http://tempuri.org/">
这是 WCF 测试客户端生成的内容,它会返回一条成功的消息:
<FileCheck xmlns="http://someserver.org/test/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
这可能是确实是新手问题,但是是否有一个我忽略的设置可以调整 xmlns 值?我尝试在我的项目中搜索“tempuri”,但找不到它,所以我打赌我忽略了某个地方的默认设置。
2011 年 2 月 8 日更新:Maurice 的最新提示成功了!我需要将正确的命名空间添加到我的 Send 工作流活动的 ServiceContractName 属性中。
I'm having a really hard time trying to find a resource or online tutorial that explicitly walks you through setting up a WF4 workflow activity that can call out to an external web service. All the videos and online samples I've come across simply demonstrate how to consume a web service that's part of your Visual Studio solution, but my situation entails calling out to a web service on a non-Microsoft server.
I have a service reference added to my VS2010 workflow console project for the web service in question, and it's pointing to the WSDL of the external web service. So far, so good (I think). I have a very basic workflow sequence, using a SendAndReceiveReply workflow control to communicate with the external server, and I believe I have the Send piece configured correctly. The ReceiveReplyForSend is giving me trouble, however, and I'm not sure if I have its Content options set up the right way. I'm invoking an operation called FileCheck, which at the moment for testing purposes always returns a value of 1 like this:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<FileCheckResponse>
<FileCheckResult>1</FileCheckResult>
</FileCheckResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
If I try to run this, however, I get the error "Badly formed SOAP message." For what it's worth, my ReceiveReplyForSend has a single parameter set up called FileCheckResult, though I don't know if that's the correct way to get the above value.
I can put a breakpoint at either activity, but I have no idea how to see what the SOAP call looks like at that point. Can someone either give me some workflow Send/Reply debugging tips or point me in the direction of an excellent step-by-step tutorial of how to consume an external web service in WF4?
Update on Feb. 2, 2011: Thanks to Maurice's suggestion, I see exactly what is failing now. The web service call in my workflow is failing because Visual Studio is generating a reference to the wrong namespace in my workflow Send call. Here is the single bit of XML that is wrong in the SOAP message - I'll leave off the rest of the SOAP envelope for succinctness:
<FileCheck xmlns="http://tempuri.org/">
This is what the WCF Test Client generates, which gets a successful message in return:
<FileCheck xmlns="http://someserver.org/test/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
This is probably a really newbie question, but is there a setting somewhere that I'm overlooking that adjusts the xmlns value? I tried searching for "tempuri" in my project, but it's nowhere to be found, so I bet I'm overlooking a default setting somewhere.
Update on February 8, 2011: Maurice's latest tip did the trick! I needed to add the proper namespace to the ServiceContractName property for my Send workflow activity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加对外部 Web 服务的引用并不比同一 VS2010 解决方案中的引用难多少。仅在这种情况下,您需要提供 VS2010 可以找到 Web 服务 WSDL 的 URL。由于通信机制是标准 WSDL 和 SOAP,因此调用其他服务应该不会有问题。
如果您想调试消息,最好使用的工具是 Fiddler。它可以让您查看传输中的消息,甚至动态构建请求。如果您有一个可以使用相关服务的现有客户端,您可以监视其消息并将其与您正在发送的消息进行比较。如果服务不使用复杂的自定义数据类型,WCF 测试客户端是检查服务是否使用标准 .NET 客户端应用程序进行响应的好方法。
SOAP 名称空间是 ServiceContractName 的一部分。使用以下语法
Adding a reference to an external web service is not much harder than one that is part of the same VS2010 solution. Only in this case you need to provide the URL where VS2010 can find the web service WSDL. As the communications mechanism is standard WSDL and SOAP there should not be a problem in calling the other service.
If you want to debug messages the best tool to use is Fiddler. It will let you see messages on the wire and even build request on the fly. If you have an existing client that can work with the service in question you can monitor its messages and compare them with the messages you are sending. Provided the service doesn't use complex and custom data types the WCF Test Client is a good way to check if the service responds with a standard .NET client app.
The SOAP namepsace is part of the ServiceContractName. Use the following syntax