日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SilverLight学习笔记--WCF服务

發(fā)布時間:2024/8/22 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SilverLight学习笔记--WCF服务 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

編寫WCF服務(wù)接口

?

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

?

namespace SilverlightApplication11.Web

{

??? // 注意: 如果更改此處的接口名稱 "IMyWCFService",也必須更新 Web.config 中對 "IMyWCFService" 的引用。

??? [ServiceContract]

??? public interface IMyWCFService

??? {

??????? [OperationContract]

??????? string ReturnXML();

??? }

}

?

編寫服務(wù)類

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

?

namespace SilverlightApplication11.Web

{

??? // 注意: 如果更改此處的類名 "MyWCFService",也必須更新 Web.config 中對 "MyWCFService" 的引用。

??? public class MyWCFService : IMyWCFService

??? {

??????? public string ReturnXML()

??????? {

??????????? string s;

??????????? s = @"<body IsMember='true'>

????????????????? <form_LRB>

?????? ?????????????<YYSRBQ>3536456.98</YYSRBQ>

??????????????????? <YYCBBQ>456798.00</YYCBBQ>

??????????????????? <XSFYBQ>3456.00</XSFYBQ>

??????????????????? <YYLRBQ>255456.32</YYLRBQ>

????????????????? </form_LRB>

????????????????? <head>

??????????????????? <createTime>2008-12-10</createTime>

??????????????????? <form>

????????????????????? <formId>ADGH4368FDG3465</formId>

????????????????????? <instanceId>DG2H9J-DG22HG-ASF42F-55FFG</instanceId>

??????????????????? </form>

????????????????? </head>

?????????? ???????<base>

??????????????????? <NSRMC>東莞市愉達(dá)玻璃裝飾工程有限公司</NSRMC>

????????????????? </base>

??????????????? </body>";

?

??????????? return s;

??????? }

??? }

}

?

?

修改Web.config

特別注意一定要把binding 改為:basicHttpBinding默認(rèn)是wsHttpBinding,否則會出錯提示“運(yùn)行出錯“System.ServiceModel.ProtocolException

?

???? <system.serviceModel>

???????? <behaviors>

????????????? <serviceBehaviors>

?????????????????? <behavior name="SilverlightApplication11.Web.MyWCFServiceBehavior">

?????????????????????? <serviceMetadata httpGetEnabled="true"/>

?????????????????????? <serviceDebug includeExceptionDetailInFaults="false"/>

?????????????????? </behavior>

????????????? </serviceBehaviors>

???????? </behaviors>

???????? <services>

????????????? <service behaviorConfiguration="SilverlightApplication11.Web.MyWCFServiceBehavior" name="SilverlightApplication11.Web.MyWCFService">

?????????????????? <endpoint address="" binding="basicHttpBinding" contract="SilverlightApplication11.Web.IMyWCFService">

?????????????????????? <identity>

??????????????????????????? <dns value="localhost"/>

?????????????????????? </identity>

?????????????????? </endpoint>

?????????????????? <endpoint address="mex" binding="basicHttpBinding" contract="IMetadataExchange"/>

????????????? </service>

???????? </services>

???? </system.serviceModel>

?

引用代理類

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using SilverlightApplication11.MyWCF;

using System.Xml;

using System.IO;

using System.ServiceModel.Channels;

using System.ServiceModel;

?

namespace SilverlightApplication11

{

??? public partial class Page : UserControl

??? {

??????? public Page()

??????? {

??????????? InitializeComponent();

??????????? GetService();

??????? }

?

??????? private void GetService()

??????? {

??????????? Binding binding = new BasicHttpBinding();

??????????? EndpointAddress endPoint = new EndpointAddress("http://localhost:4162/MyWCFService.svc");

?

??????????? MyWCFServiceClient Mywcf = new MyWCFServiceClient(binding, endPoint);

??????????? Mywcf.ReturnXMLCompleted += new EventHandler<ReturnXMLCompletedEventArgs>(wcf_ReturnXMLCompleted);

??????????? Mywcf.ReturnXMLAsync();

??????? }

?

??????? void wcf_ReturnXMLCompleted(object sender, ReturnXMLCompletedEventArgs e)

??????? {

??????????? if (e.Error == null)

??????????? {

??????????????? using (XmlReader responseReader = XmlReader.Create(new StringReader(e.Result)))

??????????????? {

?

??????????????????? responseReader.ReadToFollowing("YYSRBQ");

??????????????????? decimal YYSRBQ = responseReader.ReadElementContentAsDecimal();

??????????????????? responseReader.ReadToFollowing("YYCBBQ");

??????????????????? decimal YYCBBQ = responseReader.ReadElementContentAsDecimal();

??????????????????? responseReader.ReadToFollowing("YYLRBQ");

??????????????????? decimal YYLRBQ = responseReader.ReadElementContentAsDecimal();

??????????????????? responseReader.ReadToFollowing("instanceId");

??????????????????? string instanceId = responseReader.ReadInnerXml();

??????????????????? responseReader.ReadToFollowing("NSRMC");

??????????????????? string name = responseReader.ReadInnerXml();

?

??????????????????? OutputText.Text = "表單實(shí)例:" + instanceId + ""n" + name + ""n營業(yè)收入:" + YYSRBQ + ""n營業(yè)成本:" + YYCBBQ + ""n營業(yè)利潤:" + YYLRBQ;

??????????????? }

??????????? }

?

??????? }

??? }

}

轉(zhuǎn)載于:https://www.cnblogs.com/starcrm/archive/2008/12/10/1351780.html

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的SilverLight学习笔记--WCF服务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。