Workflow Service netTcpContextBinding如何publish metadata
最近碰到一个用netTcpContextBinding host workflow service 的问题。一直碰到远程主机强制关闭连接的问题,问题出在没有publish metadata。一般情况下会添加一个endpoint来publish metadata:
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
但是workflow service没有实现IMetadataExchange contract, 所以没法通过这种方式publish metadata。后来做WCF的同事给了一个办法通过http的方式来publish metadata,相关的配置如下:
<serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8081/Service2/mex"/>
app.config:
<system.serviceModel> <protocolMapping> <add scheme="net.tcp" binding="netTcpContextBinding"/> </protocolMapping> <bindings> <!-- Following is the expanded configuration section for a NetTcpBinding. Each property is configured with the default values. See the Message Security, and Transport Security samples in the WS binding samples to learn how to configure these features. --> <netTcpContextBinding> <binding closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/> <security mode="Transport"> <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/> </security> </binding> </netTcpContextBinding> </bindings> <behaviors> <serviceBehaviors> <behavior> <serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True"/> <!--<serviceMetadata httpGetEnabled="True"/>--> </behavior> <behavior name="Service2Behavior"> <serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="true" /> <serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8081/Service2/mex"/> <!--<etwTracking profileName="Sample Tracking Profile"/>--> </behavior> <behavior name="HttpBehavior"> <serviceDebug includeExceptionDetailInFaults="True"/> <serviceMetadata httpGetEnabled="True"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="Service2" behaviorConfiguration="Service2Behavior"> <endpoint address="net.tcp://localhost:8080/Service2" binding="netTcpContextBinding" contract="IService" /> <!--<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>--> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:8080/Service2"/> </baseAddresses> </host> </service> <service name="Service1" behaviorConfiguration="HttpBehavior"> <endpoint address="http://localhost:8080/Service1" binding="basicHttpBinding" contract="IService"></endpoint> <host> <baseAddresses> <add baseAddress="http://localhost:8080/Service1"/> </baseAddresses> </host> </service> </services> </system.serviceModel>
Host 程序:
static void Main(string[] args) { WorkflowService service = XamlServices.Load(@"http://www.cnblogs.com/Service2.xamlx") as WorkflowService; WorkflowServiceHost host = new WorkflowServiceHost(service); host.Open(); Console.WriteLine("Listening..."); Console.ReadLine(); }
这种方法很别扭,不知朋友们有没有其他办法。
另外之前在Visual Studio里面添加service reference的时候,看了一下IIS的日志,发现VS发了多个请求来获取service metadata,谁能解释一下各自对应的publish metadata方式:
2012-03-14 11:34:16 ::1 GET /Test/Services/Service1.xamlx - 80 - ::1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.1) 200 0 0 335
2012-03-14 11:34:16 ::1 GET /Test/Services/Service1.xamlx/$metadata - 80 - ::1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.1) 400 0 0 310
2012-03-14 11:34:16 ::1 GET /Test/Services/Service1.xamlx/_vti_bin/ListData.svc/$metadata - 80 - ::1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.1) 302 0 0 333
2012-03-14 11:34:16 ::1 GET /Test/Services/Service1.xamlx disco 80 - ::1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.1) 200 0 0 26
2012-03-14 11:34:16 ::1 GET /Test/Services/Service1.xamlx wsdl 80 - ::1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.1) 200 0 0 56
2012-03-14 11:34:16 ::1 POST /Test/Services/Service1.xamlx/mex - 80 - ::1 - 415 0 0 412
2012-03-14 11:34:16 ::1 POST /Test/Services/Service1.xamlx - 80 - ::1 - 415 0 0 412
2012-03-14 11:34:16 ::1 GET /Test/default.aspx - 80 - ::1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.1) 200 0 0 172
2012-03-14 11:34:16 ::1 GET /Test/Services/Service1.xamlx xsd=xsd0 80 - ::1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.1) 200 0 0 832

浙公网安备 33010602011771号