需要一些有关从 Web 服务获取响应的代码方面的帮助。你能帮我把这些点连起来吗?
好吧,我已经有一段时间没有使用网络参考了。我需要复习一下。我认为我已经掌握了获得响应所需的大约 80% 的代码,但我遗漏了一些东西。也许你可以帮助我:)
鉴于:
当指向 .wsdl
url 时,方法列表中名为 GetSomething
的 Web 方法。
这会产生一些类/对象:
GetSomethingRequest
GetSomethingCompletedEventHandler
GetSomethingCompletedEventArgs
myComplexType
我用它来创建此代码:
void someMethodToTestResponse()
{
GetSomethingRequest request = new GetSomethingRequest();
// fill in the request
request.myComplexType.Property1 = "Blah";
request.myComplexType.Property2 = "Kachoo";
GetSomethingCompletedEventHandler handler = GetSomethingCompleted_Response;
//.... ok now what?
//handler.Invoke(???)
// at this point I'm supposed to send an object for source (request maybe?)
// and a new instance of GetSomethingCompletedEventArgs but that class is
// asking for stuff that makes me think that is not the right idea.
}
void GetSomethingCompleted_Response(object source, GetSomethingCompletedEventArgs args)
{
// get the result
var result = args.Result;
}
What am我做错了吗?我缺少什么?提前致谢。
Ok, its been a while since I've worked with a Web References. I need a refresher. I think I have about 80% of the code I need to get a response going but I'm missing something. Maybe you can help me :)
Given:
A web method called GetSomething
in the list of methods when pointing to a .wsdl
url.
This produces a few classes/objects:
GetSomethingRequest
GetSomethingCompletedEventHandler
GetSomethingCompletedEventArgs
myComplexType
Which I use to create this code:
void someMethodToTestResponse()
{
GetSomethingRequest request = new GetSomethingRequest();
// fill in the request
request.myComplexType.Property1 = "Blah";
request.myComplexType.Property2 = "Kachoo";
GetSomethingCompletedEventHandler handler = GetSomethingCompleted_Response;
//.... ok now what?
//handler.Invoke(???)
// at this point I'm supposed to send an object for source (request maybe?)
// and a new instance of GetSomethingCompletedEventArgs but that class is
// asking for stuff that makes me think that is not the right idea.
}
void GetSomethingCompleted_Response(object source, GetSomethingCompletedEventArgs args)
{
// get the result
var result = args.Result;
}
What am I doing wrong? What am I missing? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要 Web 服务源代码。 Web服务可以用Java实现。创建服务引用也是一样的,因为我们真的不知道另一边是什么。
因此,尝试在 VS2008 中添加服务引用并输入工作 Web 服务的 url。 VS 将检查服务器上的 wsdl 并为您生成所需的类。
从那时起,您只需像普通方法调用一样调用该服务即可。这意味着您不必摆弄请求和 http 以及此类详细信息。所有这些都对你隐藏。除了 app.config 中的许多 WCF 设置可以更改之外。
You don't need web service source codes. The web service can be implemented in Java. Creating service reference woks the same, as we really don't know what is on the other side.
So, try Add Service Reference in VS2008 and enter the url to working web service. VS will examine the wsdl on server and generate needed classes for you.
From than on, you just call the service as some ordinary method call. Meaning you don't have to fiddle with requests and http and such details. All that is hidden from you. Except in app.config where many WCF settings can be changed.
好吧,我发现我需要找到一个
Service
类型的类。请参阅此 SO 帖子 其中提到:问题是他们提供的课程对我来说不是智能感知的,我认为这不是我想要的。
这是我解决问题的方法:
Ok, I figured out that I needed to find a
Service
type class. See this SO Post where it mentions:The issue was that the class they provide wasn't intellisensing for me and I figured it wasn't what I was looking for.
Here is how I would solve my problem: