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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

消息(6)——WCF,构建简单的WCF服务,MTOM编码

發(fā)布時間:2023/12/2 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 消息(6)——WCF,构建简单的WCF服务,MTOM编码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

構(gòu)建一個簡單的WCF服務(wù)

Web服務(wù)類似的步驟由IIS進(jìn)行宿主服務(wù)。建立的步驟:

1 新建3.5網(wǎng)站

2 添加WCF服務(wù),自動生成契約接口與實現(xiàn),這里改動一下,添加個字串參數(shù):

[ServiceContract]

public interface IFirstService

{

??? [OperationContract]

??? void DoWork(string strContent);

}

?

服務(wù)中的方法什么都不用做。

public class FirstService : IFirstService

{

??? public void DoWork(string strContent)

??? {

??? }

}

在添加WCF服務(wù)時,會自動在配置文件中添加必要的章節(jié),例如綁定和元數(shù)據(jù)發(fā)布。

?

<system.serviceModel>

? <behaviors>

??? <serviceBehaviors>

????? <behavior name="FirstServiceBehavior">

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

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

????? </behavior>

??? </serviceBehaviors>

? </behaviors>

? <services>

??? <service behaviorConfiguration="FirstServiceBehavior"

???????????? name="FirstService">

????? <endpoint address=""

??????????? ????binding="basicHttpBinding"

??????????????? contract="IFirstService">

??????? <identity>

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

??????? </identity>

????? </endpoint>

????? <endpoint address="mex"

??????????????? binding="mexHttpBinding"

??????????????? contract="IMetadataExchange" />

??? </service>

? </services>

</system.serviceModel>

?

這里把綁定改一下,改為basicHttpBinding

?

然后在測試端:新建立類庫項目,由發(fā)布的元數(shù)據(jù)生成代理,然后進(jìn)行服務(wù)請求:

[Test]

public void Test()

{

FirstInstance.FirstServiceClient client =

New FirstInstance.FirstServiceClient();

??? client.DoWork("this is a test!");

}

?

現(xiàn)在看一下消息包的情況:

這是客戶端請求的信息:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

? <s:Body>

??? <DoWork xmlns="http://tempuri.org/">

????? <strContent>this is a test!</strContent>

??? </DoWork>

? </s:Body>

</s:Envelope>

這是服務(wù)端回應(yīng)的信息:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

? <s:Body>

??? <DoWorkResponse xmlns="http://tempuri.org/"/>

? </s:Body>

</s:Envelope>

?

對于BasicHttpBinding來說,它通過http來發(fā)送soap1.1的消息。這個綁定用于配置和公開能夠與基于asmxweb service和客戶端進(jìn)行通信的終結(jié)點,以及符合ws-i basic profile 1.1標(biāo)準(zhǔn)的其它服務(wù)。

?

通過設(shè)置WCF綁定的消息編碼格式來設(shè)置傳輸過程中所使用的編碼:

<basicHttpBinding>

<binding name="firstBinding" messageEncoding="Text">

</binding>

</basicHttpBinding>

?

現(xiàn)設(shè)置BasicHttp綁定的消息編碼為文本,當(dāng)傳輸二進(jìn)制附件時,會怎么用base64編碼:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

? <s:Body>

??? <SaveImage xmlns="www.self001.com">

????? <bb>GMDggAOw==</bb>

??? </SaveImage>

? </s:Body>

</s:Envelope>

?

其中附件部分我省略了大部分,只留一小段。

當(dāng)使用MTOM編碼格式時:

--uuid:deef670a-dfd7-4a71-8d89-face6ac975dd+id=1

Content-ID: <http://tempuri.org/0>

Content-Transfer-Encoding: 8bit

Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

?

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

? <s:Body>

??? <SaveImage xmlns="www.self001.com">

????? <bb>

?? ?????<xop:Include

????????? href="cid:http%3A%2F%2Ftempuri.org%2F1%2F634057273450156250"

????????? xmlns:xop="http://www.w3.org/2004/08/xop/include"/>

????? </bb>

??? </SaveImage>

? </s:Body>

</s:Envelope>

--uuid:deef670a-dfd7-4a71-8d89-face6ac975dd+id=1

Content-ID: <http://tempuri.org/1/634057273450156250>

Content-Transfer-Encoding: binary

Content-Type: application/octet-stream

GIF89ad……省略

--uuid:deef670a-dfd7-4a71-8d89-face6ac975dd+id=1--

?

這與WSE3中使用的MTOM是相同的。

轉(zhuǎn)載于:https://www.cnblogs.com/jams742003/archive/2010/04/01/1702277.html

總結(jié)

以上是生活随笔為你收集整理的消息(6)——WCF,构建简单的WCF服务,MTOM编码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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