WF4 - 如何使用外部网络服务? [英] WF4 - How to consume external web service?

查看:24
本文介绍了WF4 - 如何使用外部网络服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难找到资源或在线教程来明确引导您设置可以调用外部 Web 服务的 WF4 工作流活动.我遇到的所有视频和在线示例都只是演示了如何使用作为 Visual Studio 解决方案一部分的 Web 服务,但我的情况需要调用非 Microsoft 服务器上的 Web 服务.

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.

我在 VS2010 工作流控制台项目中为相关 Web 服务添加了一个服务引用,它指向外部 Web 服务的 WSDL.到目前为止,很好(我认为).我有一个非常基本的工作流序列,使用 SendAndReceiveReply 工作流控件与外部服务器通信,我相信我已经正确配置了 Send 部分.但是,ReceiveReplyForSend 给我带来了麻烦,而且我不确定是否以正确的方式设置了它的 Content 选项.我正在调用一个名为 FileCheck 的操作,目前出于测试目的,它总是像这样返回 1 值:

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>

但是,如果我尝试运行此程序,则会收到错误消息格式错误的 SOAP 消息".就其价值而言,我的 ReceiveReplyForSend 设置了一个名为 FileCheckResult 的参数,但我不知道这是否是获取上述值的正确方法.

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.

我可以在任一活动上设置断点,但我不知道如何查看此时的 SOAP 调用是什么样的.有人可以给我一些工作流发送/回复调试提示,或者为我指明如何在 WF4 中使用外部 Web 服务的优秀分步教程的方向吗?

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?

2011 年 2 月 2 日更新:感谢 Maurice 的建议,我现在确切地看到了什么失败了.我的工作流中的 Web 服务调用失败,因为 Visual Studio 在我的工作流发送调用中生成对错误命名空间的引用.这是 SOAP 消息中错误的一点 XML - 为了简洁起见,我将省略 SOAP 信封的其余部分:

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

这是 WCF 测试客户端生成的内容,它会收到一条成功消息作为回报:

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

这可能是一个真正的新手问题,但是否有我忽略的设置可以调整 xmlns 值?我尝试在我的项目中搜索tempuri",但找不到,所以我敢打赌我忽略了某个地方的默认设置.

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.

2011 年 2 月 8 日更新:莫里斯的最新提示成功了!我需要为我的 Send 工作流活动的 ServiceContractName 属性添加适当的命名空间.

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 服务的引用并不比同一个 VS2010 解决方案中的引用困难多少.只有在这种情况下,您才需要提供 VS2010 可以找到 Web 服务 WSDL 的 URL.由于通信机制是标准的 WSDL 和 SOAP,因此调用其他服务应该没有问题.

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.

如果您想调试消息,最好使用的工具是 Fiddler.它将让您看到在线消息,甚至可以即时构建请求.如果您有一个可以使用相关服务的现有客户端,您可以监控它的消息并将它们与您发送的消息进行比较.如果服务不使用复杂的自定义数据类型,WCF 测试客户端是检查服务是否使用标准 .NET 客户端应用进行响应的好方法.

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.

SOAP 命名空间是 ServiceContractName 的一部分.使用以下语法

The SOAP namepsace is part of the ServiceContractName. Use the following syntax

{http://someserver.org/test/}文件服务

这篇关于WF4 - 如何使用外部网络服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆