Showing posts with label web service. Show all posts
Showing posts with label web service. 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>

Thursday, November 27, 2008

web service 使用Session

web service中使用session需要開啟EnableSession
[WebMethod(EnableSession = true, CacheDuration=0....)]

web.config中<sessionState mode="">  mode不等於none

 

.NET中session的方式是透過Cookie儲存ID,才可以延續使用。
如果是在Web service中使用session,會來存取web service就不一定是瀏覽器
可能是程式碼。

如果是程式碼的話,則需要在程式碼中使用CookieContainer

WebService ws = new WebService();
System.Net.CookieContainer container = new System.Net.CookieContainer();

ws.CookieContainer = container ;
ws.XXXX();

CookieContainer 中會保存server端傳回來的sessionId,所以就可以延續的使用。

如果有需要的話,也是可以把CookieContainer存起來,再傳到需要使用的網頁或其他程式碼。