// 建立自定義綁定 BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements);
/// <summary> /// Author:TerryLee /// Url:[url]http://www.cnblogs.com/terrylee[/url] /// </summary> /// <param name="args"></param> static void Main(string[] args) { // 建立自定義綁定 BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); // 使用自定義綁定建立通道偵聽器 IChannelListener<IReplyChannel> listener = binding.BuildChannelListener<IReplyChannel>( new Uri("http://localhost:8080/ChannelApp"), new BindingParameterCollection()); // 監聽消息 listener.Open(); Console.WriteLine("Listening for incoming channel connections"); IReplyChannel channel = listener.AcceptChannel(); Console.WriteLine("Channel accepted. Listening for messages"); channel.Open(); while (true) { RequestContext request = channel.ReceiveRequest(); // 讀取請求的消息 Message message = request.RequestMessage; Console.WriteLine("Message Received"); Console.WriteLine("Message Action: {0}", message.Headers.Action); string body = message.GetBody<string>(); Console.WriteLine("Message Content: {0}", body); // 發送響應消息 Message replymessage = Message.CreateMessage( binding.MessageVersion, "http://www.cnblogs.com/terrylee", body); request.Reply(replymessage); // 釋放對象 message.Close(); request.Close(); channel.Close(); listener.Close(); } }
<services> <service name="TerryLee.WCFAddressing.Service.CalculatorService" behaviorConfiguration="calculatorBehavior"> <host> <baseAddresses> <add baseAddress="[url]http://localhost:8887/Calculator[/url]"/> </baseAddresses> </host> <endpoint address="" binding ="basicHttpBinding" contract="TerryLee.WCFAddressing.Contract.ICalculator" name="defaultBinding" bindingConfiguration="myBindingConfiguration"> </endpoint> </service> </services> <bindings> <basicHttpBinding> <binding name="myBindingConfiguration" messageEncoding="Mtom"> <security mode="Message"></security> </binding> </basicHttpBinding> </bindings>
BasicHttpBinding binding = new BasicHttpBinding(); binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate; binding.Security.Mode = BasicHttpSecurityMode.Message; binding.MessageEncoding = WSMessageEncoding.Mtom;
BasicHttpBinding binding = new BasicHttpBinding(); binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate; binding.Security.Mode = BasicHttpSecurityMode.Message; binding.MessageEncoding = WSMessageEncoding.Mtom; CustomBinding mybinding = new CustomBinding(binding); BindingElementCollection myElements = binding.CreateBindingElements();
<services> <service name="TerryLee.WCFAddressing.Service.CalculatorService" behaviorConfiguration="calculatorBehavior"> <host> <baseAddresses> <add baseAddress="[url]http://localhost:8887/Calculator[/url]"/> </baseAddresses> </host> <endpoint address="[url]http://localhost:8887/CalculatorService[/url]" binding ="basicHttpBinding" contract="TerryLee.WCFAddressing.Contract.ICalculator" name="defaultBinding" bindingConfiguration="myBindingConfiguration"> </endpoint> </service> </services> <bindings> <basicHttpBinding> <binding name="myBindingConfiguration" messageEncoding="Mtom"> </binding> </basicHttpBinding> </bindings>
<wsdl:binding name="defaultBinding" type="tns:ICalculator"> <wsp:PolicyReference URI="#defaultBinding_policy" /> <soap:binding transport="[url]http://schemas.xmlsoap.org/soap/http[/url]" /> <wsdl:operation name="Add"> <soap:operation soapAction="[url]http://tempuri.org/ICalculator/Add[/url]" style="document" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding>
<wsp:Policy wsu:Id="defaultBinding_policy"> <wsp:ExactlyOne> <wsp:All> <wsoma:OptimizedMimeSerialization xmlns:wsoma="[url]http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization[/url]" /> </wsp:All> </wsp:ExactlyOne> </wsp:Policy>
0javascript
收藏css
Ctrl+Enter 發佈html
發佈java
取消jquery