【发布时间】:2019-10-18 05:57:42
【问题描述】:
我有 WCF 服务
[ServiceContract(Name = "Test")]
public interface ITest {
[OperationContract]
string test1();
}
[DataContract]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]
public class csTest : ITest {
public string test1() {
Thread.Sleep(60000);
return "test1";
}
}
启动它们
ServiceHost TestHost= new ServiceHost(typeof(HostHCS.Test.csTest), new Uri("http://127.0.0.1:8150/Test"));
ServiceConfigureHttp(TestHost, crtSMBHttp("127.0.0.1","Test","8150"), crtSDB(), typeof(HostHCS.Test.ITest), crtBndHttp(), ip, "Test");
TestHost.Open();
private void ServiceConfigureHttp(ServiceHost service, ServiceMetadataBehavior serviceMetadataBehavior, ServiceDebugBehavior serviceDebugBehavior, Type serviceType, BasicHttpBinding bind, string ip, string servName) {
service.Description.Behaviors.Remove(typeof(ServiceMetadataBehavior));
service.Description.Behaviors.Add(serviceMetadataBehavior);
service.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
service.Description.Behaviors.Add(serviceDebugBehavior);
service.AddServiceEndpoint(serviceType, new WSHttpBinding(),"");
service.AddServiceEndpoint(
System.ServiceModel.Description.ServiceMetadataBehavior.MexContractName,
System.ServiceModel.Description.
MetadataExchangeBindings.CreateMexHttpBinding(),
"http://127.0.0.1:8150/Test/mex");
}
private BasicHttpBinding crtBndHttp() {
BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = Int32.MaxValue;
XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
readerQuotas.MaxArrayLength = Int32.MaxValue;
readerQuotas.MaxStringContentLength = Int32.MaxValue;
readerQuotas.MaxBytesPerRead = Int32.MaxValue;
readerQuotas.MaxDepth = Int32.MaxValue;
binding.ReaderQuotas = readerQuotas;
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.OpenTimeout = new TimeSpan(1, 00, 0);
binding.CloseTimeout = new TimeSpan(1, 00, 0);
binding.SendTimeout = new TimeSpan(1, 00, 0);
binding.ReceiveTimeout = new TimeSpan(1, 00, 0);
return binding;
}
private ServiceMetadataBehavior crtSMBHttp(string ip, string servName,string port) {
ServiceMetadataBehavior myServiceMetadataBehavior = new ServiceMetadataBehavior();
myServiceMetadataBehavior.HttpGetEnabled = true;
myServiceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
return myServiceMetadataBehavior;
}
我的php代码
<?php
try{
ini_set('default_socket_timeout', 600); //120/// 6000//60000
$client = new SoapClient(
'http://127.0.0.1:8150/Test?wsdl',
array(
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => 1,
'exception' => 1,
'keep_alive' => 0,
'connection_timeout' => 60000//500000
));
$webService = $client->test1();
} catch (Exception $e) {
print 'Caught exception: '. $e->getTraceAsString(). "<br/>";
print 'Caught exception: '. $e->getMessage(). "<br/>";
var_dump($client->__getLastRequestHeaders());
print "<br/>";
var_dump($client->__getLastRequest());
print "<br/>";
var_dump($client->__getLastResponse());
print "<br/>";
}
?>
很快返回结果
捕获的异常:#0 [内部函数]: SoapClient->__doRequest('__call('test1', Array) #2 {main}
捕获异常:获取 http 标头时出错
string(204) "POST /Test HTTP/1.1 主机:127.0.0.1:8150 连接: 关闭用户代理:PHP-SOAP/7.3.2 内容类型:application/soap+xml; 字符集=utf-8; action="http://tempuri.org/Test/test1" 内容长度: 第186章
字符串(186)“”
空
也就是说,没有调用服务方法,因为结果应该在一分钟后收到。可能是什么问题,我做错了什么?
【问题讨论】: