WCF服务库示例 [英] WCF Sevice Library Examples

查看:139
本文介绍了WCF服务库示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助.......................

我是WCF服务的新手并且已经分配了一个项目,客户将通过WCF向我们发送订单。我创建了一个测试服务,接受站点号码并返回站点名称,地址,电话,传真,经理,城市,州,邮政等的所有详细信息。现在我需要创建一个客户将发送订单的服务,服务将通过IIS附加到网站,并将只收听传入的请求。任何帮助都将非常感谢...



David

Help.......................
I am new to WCF Services and have been assigned a project, where customer will send us orders through WCF. I have created a test service that accepts a site number and returns all the details of site name, address, telephone, fax, manager, city, state, zip etc. Now I need to create a service where client will send order(s), service will be attached to Website through IIS and will just listen for incoming requests. Any help at all will be greatly appreciated...

David

推荐答案

请下载基本骨架我编写的WCF解决方案。





http://sdrv.ms/16Bkt2r [ ^ ]



别误会我的意思。首先,您需要了解WCF的基础知识。



1.地址,装订,合同。

2.如何创建和使用服务

3.如何托管服务。



您必须对服务进行编码以接收采购订单作为流。以下是您可以使用的服务合同。



Please download the basic skeleton of WCF Solution which I coded for you.


http://sdrv.ms/16Bkt2r[^]

Don't get me wrong. First of all you need to understand the basics of WCF.

1. The Address , Binding, Contract.
2. How to Create and Consume Service
3. How to host the service.

You will have to code the service to receive Purchase Orders as Stream. Below is the Service Contract which you can go for.

[ServiceContract]
   public interface IFileUploadService
   {
        [OperationContract]
        UploadResponse Upload(UploadRequest uploadRequest);
   }





这是UploadRequest消息合约。





Here's the UploadRequest Message Contract.

[MessageContract]
    public class UploadRequest
    {
        [MessageBodyMember]
        public Stream Stream { get; set; }
    }





这是响应。现在它只返回UploadSucceeded设置为True的响应。你必须适当改变它





Here's the Response. For now it just returns the response with UploadSucceeded set to True. You will have to change it suitably

[MessageContract]
   public class UploadResponse
   {
       [MessageBodyMember]
       public bool UploadSucceeded { get; set; }
   }





最后这里是服务实施。您使用StreamReader阅读流内容的位置。获取所有内容并保存在StringBuilder中,以便以后可以将其保存在数据库中。





And finally here's the Service Implementation. Where you read the Stream Content using StreamReader. Get all the contents and hold in StringBuilder so that later you can save the same in database.

public class PurchaceOrderService : IFileUploadService
   {
       public UploadResponse Upload(UploadRequest uploadRequest)
       {
           var fileContentStringBuilder = new StringBuilder();

           using (StreamReader sr = new StreamReader(uploadRequest.Stream))
           {
               string line;
               while ((line = sr.ReadLine()) != null)
               {
                   fileContentStringBuilder.AppendLine(line);
               }
           }

           var purchaceOrder = fileContentStringBuilder.ToString();
           
           // TOTO: Save the Purchace Order to Database.

           // Return the Response.
           
           return new UploadResponse
                    {
                        UploadSucceeded = true
                    };
       }
   }


这篇关于WCF服务库示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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