Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Wednesday, December 10, 2008

在Https中建立WCF service

在web.config中設定相關字串

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IWGWCF" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>

<services>
<service behaviorConfiguration="ServiceBehavior" name="WGWCF">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWGWCF"
name="serverEnd" contract="IWGWCF" />
<host>
<baseAddresses>
<add baseAddress="https://17-00sf300-01/WGWS" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>

<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
httpsGetUrl="https://17-00sf300-01/WGWS/" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="WGWCFBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
httpsGetUrl="https://17-00sf300-01/WGWS/" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

WGWCF 使用session

在binding中設定好ReliableSession.enabled = True即可

 

另外在Contract中,可以設定SessionMode=SessionMode.Requied

[ServiceContract(Name = "IWGWCF", SessionMode = SessionMode.Required)]
public interface IWGWCF
{
[OperationContract]
string search(string keyword, int start, int returnCount);


}

在behavior中可以設定session使用的時間周期

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class WGWCF : IWGWCF
{
public string search(){

}
}

Tuesday, December 2, 2008

加入服務參考

有別於'加入WEB參考',WCF所提供的服務需要透過'加入服務參考'來讓client使用。

在開發client程式中,使用vs 2008升級了原本的舊程式碼,卻怎麼也找不到'加入服務參考'。由於轉換的時候把專案轉成了'網站'形式,以為是因為網站無法使用'服務參考'。

在這篇文章中有說明 http://msdn.microsoft.com/zh-tw/library/bb398791.aspx (......"只有以 .NET Framework 3.5 為目標的網站和以 .NET Framework 3.0 或 .NET Framework 3.5 為目標的 Web 應用程式專案,才有 [加入服務參考] 對話方塊。"........... )

現在可以使用wcf的服務了。