简体   繁体   English

WCF Web服务PUT数据

[英]WCF Webservice PUT data

I've created a web service which receives a xml file like this: 我已经创建了一个Web服务,该服务接收如下所示的xml文件:

- <ns0:Root xmlns:ns0="http://SimpleBizTalkOrchestration.ReceiveSchema">
  <FirstName>Ron</FirstName> 
  <LastName>Swan</LastName> 
  </ns0:Root>

and passes it to an BizTalk Orchestration. 并将其传递给BizTalk业务流程。

This is the webservice i need to call. 这是我需要致电的网络服务。

   http://localhost/BizTalkWcfService/SimpleService.svc

My question is how do you call a WCF web service and pass data to it? 我的问题是如何调用WCF Web服务并将数据传递给它?

I've seen many tutorials which request data from the web service but cant find any that pass information to the service. 我看过许多教程,它们从Web服务请求数据,但是找不到将信息传递给服务的任何教程。

Thanks in advance for any advice. 在此先感谢您的任何建议。

I've seen many tutorials which request data from the web service but cant find any that pass information to the service. 我看过许多教程,它们从Web服务请求数据,但是找不到将信息传递给服务的任何教程。

That is because, regardless of whether you're requesting data or posting data, when consuming a service in WCF you write the exact same code . 这是因为,无论您是请求数据还是发布数据,在WCF中使用服务时,您都编写完全相同的代码

The only thing which influences the outcome when you call the service is the service endpoint definition. 调用服务时,唯一会影响结果的是服务端点定义。 For example, a service defined as 例如,定义为

[ServiceContract]
SomeData GetData();

will return data when you call it. 调用时将返回数据。 A service defined as 定义为

[ServiceContract]
void PushData(SomeData data);

will accept the data you send when you call it. 调用时将接受您发送的数据。 Regardless of which, the method of consuming the service is the same. 无论哪种方式,使用服务的方法都是相同的。 You create a client, either via a proxy constructed from service metadata , or using WCF channels , create a request, and call the service. 您可以通过从服务元数据构造的代理或使用WCF通道创建客户端,创建请求并调用服务。

WCF SOAP is used to communicate with other services or programs. WCF SOAP用于与其他服务或程序进行通信。 So actually you need to write a dummy program or web site. 因此,实际上您需要编写一个虚拟程序或网站。 By developing of this test application (I'll call it "testApp") you can "consume a wcf service". 通过开发此测试应用程序(我将其称为“ testApp”),您可以“使用wcf服务”。 After that every call to this service would be as easy as a call to a function in external library. 之后,每次调用此服务都将像调用外部库中的函数一样容易。 I assume you should better create a new windowsForms or WebForms or whatever project in the same solution, after that consume the service and so you will be able to send and get information to/from this WCF service in your windowsForms or WebForms app (the testApp). 我假设您最好在同一解决方案中创建一个新的WindowsForms或WebForms或任何项目,然后再使用该服务,因此您将能够在WindowsForms或WebForms应用程序(testApp中)向该WCF服务发送信息或从中获取信息。 )。 An example: http://www.csharptutorial.in/34/csharp-net-how-to-consume-a-wcf-web-service-in-visual-studio-2010 范例: http//www.csharptutorial.in/34/csharp-net-how-to-consume-a-wcf-web-service-in-visual-studio-2010

Check out SoupUI for testing your web service. 查看SoupUI以测试您的Web服务。

Connect using the following address: http://localhost/BizTalkWcfService/SimpleService.svc?wsdl 使用以下地址连接: http://localhost/BizTalkWcfService/SimpleService.svc?wsdl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM