WSSF:ME - how to consume a service

New to WCF/WSSF? Visit http://code.msdn.microsoft.com/ServiceFactory
  • Topics Covered
    • Hands-on Lab continued - how to consume a WCF service (with and without Config file)
    • Assumptions that had me googling and burning hours...
    • Configure IIS for WCF
    BYA.Mfg.SCM.Svc.WCF :: Tests :: BYA.Mfg.SCM.Svc.WCF.Client :: MainForm.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Diagnostics;

  9. using BYA.Mfg.SCM.Svc.WCF.Client.MaterialMgmtProxy;

  10. namespace BYA.Mfg.SCM.Svc.WCF.Client
  11. {
  12.     public partial class MainForm : Form
  13.     {
  14.         PartsMgmtServiceContractClient client;

  15.         public MainForm()
  16.         {
  17.             InitializeComponent();
  18.             client = new PartsMgmtServiceContractClient("DefaultEndpoint");
  19.         }

  20.         // Utilizes App.Config
  21.         private void ExecuteButton_Click(object sender, EventArgs e)
  22.         {
  23.             // Configure the request utilizing input - valid input
  24.             // are "one" and "two" - all others will return 0 values
  25.             DemandRequest request = new DemandRequest();
  26.             request.AircraftPart = new AircraftPart();
  27.             request.AircraftPart.Part = SearchText.Text;

  28.             ResultsGrid grid = new ResultsGrid(client.GetRequirementDemand(request));
  29.             grid.Show();
  30.         }

  31.         //-- OR --

  32.         // Utilizes Channel
  33.         private void ExecuteButton_Click(object sender, EventArgs e)
  34.         {
  35.             // Configure the request utilizing input - valid input
  36.             // are "one" and "two" - all others will return 0 values
  37.             DemandRequest request = new DemandRequest();
  38.             request.AircraftPart = new AircraftPart();
  39.             request.AircraftPart.Part = SearchText.Text;

  40.             BasicHttpBinding binding = new BasicHttpBinding();
  41.             EndpointAddress endPoint = new EndpointAddress("http://localhost:2035/BYA.Mfg.SCM.Svc.WCF.Host/MaterialMgmt.svc");

  42.             ChannelFactory<PartsMgmtServiceContract> channelFactory =
  43.             new ChannelFactory<PartsMgmtServiceContract>(binding, endPoint);

  44.             PartsMgmtServiceContract service = channelFactory.CreateChannel();

  45.             DemandResponse response = service.GetRequirementDemand(new DemandRequest1(request));

  46.             ResultsGrid grid = new ResultsGrid(response.PartLevel);
  47.             grid.Show();

  48.         }
  49.     }
  50. }



BYA.Mfg.SCM.Svc.WCF :: Source :: Service Interface :: BYA.Mfg.SCM.Svc.WCF.ServiceImplementation :: PartsMgmtService.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using BYA.Mfg.SCM.Svc.WCF.DataContracts;
  6. using BYA.Mfg.SCM.Svc.WCF.BusinessEntities;
  7. using BYA.Mfg.SCM.Svc.WCF.MessageContracts;

  8. namespace BYA.Mfg.SCM.Svc.WCF.ServiceImplementation
  9. {
  10.     public partial class PartsMgmtService
  11.     {
  12.         public override DemandResponse GetRequirementDemand(DemandRequest request)
  13.         {
  14.             // The following object represents the
  15.             // business entity returned from the business logic
  16.             ItemLevel itemLevel;
  17.             itemLevel = new ItemLevel();

  18.             switch (request.AircraftPart.Part)
  19.             {
  20.                 case "one":
  21.                     itemLevel.Expecting = 10;
  22.                     itemLevel.Usable = 100;
  23.                     break;
  24.                 case "two":
  25.                     itemLevel.Expecting = 20;
  26.                     itemLevel.Usable = 200;
  27.                     break;
  28.                 default:
  29.                     itemLevel.Expecting = 0;
  30.                     itemLevel.Usable = 0;
  31.                     break;
  32.             }

  33.             PartLevel partLevel;
  34.             partLevel = TranslateBetweenItemLevelAndPartLevel.TranslateItemLevelToPartLevel(itemLevel);
  35.             DemandResponse response = new DemandResponse();
  36.             response.PartLevel = partLevel;

  37.             return response;
  38.         }
  39.     }
  40. }
Being new to the WSSF I've made some bad assumptions.... As such I plan to extend this message thread as I stumble across them (no pun intended) along with their resolutions in hopes of preventing the next newbie (with no knowledge of WCF and WSSF) from making the same assumptions and losing valuable hours. Comments will be within the context of the BlueYonderAirLines lab.

Assumption: Exercise 3 - Wiring up the data contracts uses a Message for Request and a XSD Message for Response, not being familiar with either of these I assumed that request and response required these types. While researching the following assumptions I discovered that a message is used to reference a service.datacontract item where a XSD Message allows you to reference types located in schemas or xsd files (ref: http://www.codeplex.com/servicefactory/Thread/View.aspx?ThreadId=21890)

Assumption: I could create an XSD file using the VS DataSet design tool and use it as an XSD Message. Querying "XSD Message" in the forum did not yield any understandable results (I don't yet share a common core of experience with the community) however this message thread http://www.codeplex.com/servicefactory/Thread/View.aspx?ThreadId=3787 provided a Microsoft link that suggest a "subset of the XML Schemea (XSD) used by the DataContractSerializer" is used. (MS: http://msdn.microsoft.com/en-us/library/ms733112.aspx). My assumption is that the PartLevel.xsd file referenced in step 4 of Exercise 3 was manually created.

Assumption: Visual Studio will Launch Development Server. I missed one step in Exercise 7 which sent me configuring my firewall and chasing google trails - because my connection was actively refused. Step 18 notes "Right-click this project again and select View In Browser to expose the service so the metadata will be available to generate the proxy from"

Issue: I started getting an invalid port message after experimenting (making changes and recompiling). The WCF :: Tests :: BYA.Mfg.SCM.Svc.WCF.Client's App.Config file appends <basicHttpBinding> statements - in my case I learned real quick about <endpoint> as I had multiple entries (with different ports). I cleaned out all of the entries but the "DefaultEndpoint" and all was happy again.

Issue: Couldn't compile source code after removing FXCop references (over 200 errors). Used binaries for prototype but usually use source for development; fix was to remove VS2005 SDK (ref: http://www.codeplex.com/servicefactory/Thread/View.aspx?ThreadId=25149).

Assumption: (On the documention's part) That we would know how to consume a WCF / WSSF - the following represents the only two classes I had to update to provide a service and consume it.


source link: http://www.codeplex.com/servicefactory/Thread/View.aspx?ThreadId=27655
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值