询问者
Duplex 双工 本地正常 发布到外网服务器后,连接超时

问题
-
如题:
服务器端口已打开,在本地可以添加服务引用。就是总是连接超时。
服务web.config.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="aa"> <serviceMetadata httpGetEnabled="true" httpGetUrl="http://222.222.222.111:8084/calculatorservice/mex" /> <serviceDebug includeExceptionDetailInFaults="true" /> <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <wsDualHttpBinding> <binding name="wsdualbind" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"> <reliableSession ordered="true" inactivityTimeout="00:10:00" /> <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/> <security mode="None"> <message clientCredentialType="Windows" negotiateServiceCredential="true" /> </security> </binding> </wsDualHttpBinding> </bindings> <services> <service behaviorConfiguration="aa" name="FormService.Calculator"> <clear /> <endpoint address="http://222.222.222.111:8084/calculatorservice" binding="wsDualHttpBinding" bindingConfiguration="wsdualbind" name="wsdual" contract="FormService.ICalculator" /> </service> </services> </system.serviceModel> </configuration>
客户端:<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <wsDualHttpBinding>
//这个地址是在ip138上看到了本机地址,本机是路由器中的ip 192.168.1.2
<binding clientBaseAddress="http://123.125.166.162:8084/" name="wsdual" 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"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" /> <security mode="None"> <message clientCredentialType="Windows" negotiateServiceCredential="true" /> </security> </binding> </wsDualHttpBinding> </bindings> <client> <endpoint address="http://222.222.222.111:8084/calculatorservice" binding="wsDualHttpBinding" bindingConfiguration="wsdual" contract="Service.ICalculator" name="wsdual" /> </client> </system.serviceModel> </configuration>clientBaseAddress="http://123.125.166.162:8084/"
上面的地址是从ip138上查看到的本机的地址。
错误提示:The open operation did not complete within the allotted timeout of 00:00:59.9949997. The time allotted to this operation may have been a portion of a longer timeout.
[ServiceContract(Namespace = "http://schemas.xinhaijulan.com/demos/DualHttpBinding", CallbackContract = typeof(ICalculatorCallBack))] public interface ICalculator { [OperationContract(IsOneWay=true)] void Add(int a,int b); } public interface ICalculatorCallBack { [OperationContract] void Result(string msg); } [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] public class Calculator : ICalculator { public void Add(int a, int b) { ICalculatorCallBack callback = OperationContext.Current.GetCallbackChannel<ICalculatorCallBack>(); callback.Result((a + b).ToString()); } } 开启服务: private void button1_Click(object sender, EventArgs e) { ServiceHost host = new ServiceHost(typeof(Calculator)); try { host.Closed += new EventHandler(host_Closed); host.Open(); label1.Text = "打开"; } catch (Exception ex) { string a = ex.Message; label1.Text = a; } }
//回调类 public class Class1 : Service.ICalculatorCallback { public void Result(string msg) { Console.WriteLine(msg); } } //客户端调用 private void button1_Click(object sender, EventArgs e) { Thread newThread = new Thread(new ThreadStart(this.aa)); newThread.Start(); } public void aa() { try { Class1 c = new Class1(); InstanceContext instanceContext = new InstanceContext(c); Service.CalculatorClient client = new Service.CalculatorClient(instanceContext); client.Add(2, 3); this.Invoke((Action)(() => { label1.Text = "ok"; })); } catch (Exception ex) { string a = ex.Message; MessageBox.Show(a + ex.StackTrace); } }
注:上面ip并非真实。- 已编辑 蔡风 2011年11月5日 8:49
全部回复
-
-
你可以在服务端使用WCF Tracing来查看每个WCF调用信息。
#enable WCF tracing.
http://blogs.msdn.com/b/madhuponduru/archive/2006/05/18/601458.aspx你可以在配置文件中将相应的timout的值设置大一些(如:receiveTimeout,sendTimeout)
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework -
本机的防火墙关了,还是连接不上。
后来用了net.tcp邦定,可以运行成功了。
不明白为什么wsDualHttpBinding不行,是哪配置有问题?
WPF- 已编辑 Michael Joey 2011年12月13日 9:35